Ok! Welcome to part two… What is the idea behind this second part… Well with Powershell 2.0 we have now Powershell remoting that allow us to run commands on remote machines… When we are thinking about automating tasks we would like to execute some powershell scripts on servers or machines around our company.
Ok in example 2 we have two servers:
DEMOAD.demo.local – active directory server
DEMORDSSRV01.demo.local – member server (in fact remote desktop server but it is not an important info… 🙂 )
Let say that we will be connected to DEMOAD.demo.local and we will prepare a script and schedule it to get information from DEMORDSSRV01.demo.local
1. First we need to enable Powershell remoting on DEMORDSSRV01.demo.local using Powershell cmdlet:
2. We need to test if remoting works so we can test it by using cmdlet:
Test-WSMan -ComputerName DEMORDSSRV01
this cmdlet should be run on DEMOAD machine. If everything is ok you should receive something like:
wsmid : http://schemas.dmtf…
ProductVendor: Microsoft Corporation
ProductVersion: OS: 0.0.0 SP: 0.0 Stack: 2.0
If you did not enable remoting on DEMORDSSRV01.demo.local you will receive:
Test-WSMan : The WinRM client cannot complete the operation…
If you receive this error try to reenable Powershell Remoting by using cmdlet: Enable-PSRemoting
3. Create a powershell script (a txt file that has extension .ps1) for example remoteprocess.ps1 edit it with your notepad and write inside the cmdlet:
get-process -computername demordssrv01 | out-file c:remoteprocess.txt
this script will request process list from demordssrv01 and the result will be pipelined to txt file called c:remoteprocess.txt on demoad.demo.local – so from machine that will execute the query.
4. When you are done with script you just need to create a Basic Task in Task Scheduler. You can check my prevous article (part1) to see other steps to do that.