Wanted to find what account our NetBackup service is running under on a bunch of servers –
1 |
"server1", "server2", "server3", "server4" | %{ Get-WmiObject Win32_Service -ComputerName $_ | ?{ $_.Name -eq "NetBackup Client Service" } } | ft SystemName,Name,StartName |
You have to use WMI for this coz Get-Service
doesn’t show the Log On As user.
Wheee!! Had a tweet from Jeffrey Snover for this post.
@rakheshster Try this form to speed things up:
Gwmi Win32_Service -cn S1,S2,S2 -Filter ‘Name = “NetBackup Client Service”‘ | ft— jsnover (@jsnover) June 1, 2016
Following on that tweet I noticed something odd.
The following command works –
1 |
Get-WmiObject Win32_Service -cn server1,server2 -Filter 'Name= "NetBackup Client Service"' |
Or this –
1 |
Get-WmiObject Win32_Service -cn @("server1","server2") -Filter 'Name= "NetBackup Client Service"' |
In the second one I am explicitly casting the arguments as an array.
But this variant doesn’t work –
1 2 |
$Servers = "server1","server2" Get-WmiObject Win32_Service -cn $Server -Filter 'Name= "NetBackup Client Service"' |
That generates the following error –
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ Get-WmiObject Win32_Service -cn $Servers -Filter ‘Name= “NetBackup Client Service …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommandGet-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ Get-WmiObject Win32_Service -cn $Servers -Filter ‘Name= “NetBackup Client Service …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
The error is generated for each entry in the array.
It looks like when I pass the list of servers as an array variable PowerShell uses a different way to connect to each server (PowerShell remoting/ WinRM) while if I specify the list in-line it behaves differently. I didn’t search much on this but found this Reddit thread with the same issue. Something to keep in mind …