One of the cool things about BatchPatch is that you can use it with your own scripts to retrieve information from many target computers. For the sake of this blog posting, let’s look at an example where an administrator wants to retrieve the count of CPU cores from his/her target machines.
Let’s start with the script. In this case I’ve written a vbscript to retrieve the count of CPUs by socket, core, and logical processor. First let’s take a look at the script, and then below I’ll show you how to execute the script from within BatchPatch.
Here is a what it looks like when we run the script manually from the command line:
Here is the actual script:
Download CPUCoreCount.vbs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 'Gets the number of CPU Sockets, Cores, and Logical Processors. Cocobolo Software LLC April 2014. 'usage: cscript.exe CPUCoreCount.vbs COMPUTERNAME strComputer = WScript.Arguments(0) on error resume next Err.Clear 'strComputer = TextBox.value 'InputBox("Enter the Computer Name or IP address") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 'Get OS Version for CPU info Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems OSVersion = objOperatingSystem.Caption Next 'Get Processor Info (note: it can take a long time to pull info from this class) Sockets = 0 Cores = 0 LogicalProcessors = 0 WMISupport = 1 If InStr(OSVersion,"2003") or InStr(OSVersion,"XP") or InStr(OSVersion,"2000") Then WMISupport = 0 End If Set colProc = objWMIService.ExecQuery("Select * from Win32_Processor") For Each objProc in colProc ProcessorName = objProc.Name Sockets = Sockets + 1 Cores = Cores + objProc.NumberOfCores If Err.Number <> 0 Then Cores = Err.Description Err.Clear End If LogicalProcessors = LogicalProcessors + objProc.NumberOfLogicalProcessors Next If WMISupport = 0 Then LogicalProcessors = Sockets Sockets = "Property is not supported for this OS" Cores = "Property is not supported for this OS" End If wscript.echo("Sockets: " & Sockets & vbCrLf & "Cores: " & Cores & vbCrLf & "Logical Procs: " & LogicalProcessors) |
Using ‘Local process/command’ vs ‘Remote process/command’
BatchPatch has the ability to execute scripts locally on the computer that runs BatchPatch, or remotely on the target computers themselves. Depending on the needs in a particular situation, we decide which option makes more sense. In this particular case, if you take a look at the above vbscript, you can see that the script actually takes a target computer name as an argument. Since this script is able to give us information about remote computers without having to run it directly on remote computers, we will simply choose to execute it locally on the machine that runs BatchPatch, and we’ll pass our target computer names to the script so that we can retrieve information about those target computers. However, if the script were only able to retrieve information about the local computer without having the built-in capability of querying remote computers, then we would instead use BatchPatch to execute the script remotely on the target computers.
So, to be very clear…
- If a script has built-in capability to query remote computers, then the script should be run on the local computer that runs BatchPatch using Actions > Local process/command.
- If the script does NOT have built-in capability to query remote computers and it can ONLY retrieve information about the local computer that its being executed on, then the script must be executed remotely on each target computer using Actions > Remote process/command.
To execute the CPUCoreCount.vbs script using BatchPatch:
- In BatchPatch, highlight the target computers and select Actions > Local process/command > Create/modify local command 1
- Enter the actual local command/process. Note that because our script accepts a computer name as the first/only argument, we specify the $computer as our argument. When BatchPatch sees $computer it knows to substitute the actual computer name from the Hosts column. This way we are able to execute the local script one time for each machine in the grid.
- Now to execute the script, highlight the target computers and select Actions > Local process/command > Execute local command 1
- Finally, let’s examine the output. We have the option to either look at each computer’s result individually by middle-clicking on the cell that contains the output, or we could export an HTML report (File > Export), or we could even just copy and paste the grid contents into a spreadsheet program such as Microsoft Excel if it needs to be customized before presenting.