PowerShell - op_Addition, RPC server is unavailable

Cerulean

[H]F Junkie
Joined
Jul 27, 2006
Messages
9,476
run.bat
Code:
powershell C:\Temp\testps\testps2.ps1>C:\Temp\testps\log.txt

testps2.ps1
Code:
# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory

# Query Active Directory for computers running a Server operating system
$Servers = Get-ADComputer -Filter {Name -like "corp-it-vdi-*"}

# Loop through the list to query each server for login sessions
ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElement | Sort Count}

run.bat works fine. The issue is with the execution of the PowerShell script. When I run it in the PowerShell URE console, I get this output:

Code:
_________________________________________________________________________________________________________________________
PS C:\Temp\testps> .\testps2.ps1
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer] doesn't contain a method named 'op_Additi
on'.
At C:\Temp\testps\testps2.ps1:8 char:41
+ ForEach ($Server in $Servers) {$Server + <<<<  "`n`n"; get-wmiobject win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:63
+ ForEach ($Server in $Servers) {$Server + "`n`n"; get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElem
ent | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 

_________________________________________________________________________________________________________________________

Clearly I don't understand what I'm doing, but it would be educational to figure out the solution to this challenge.

I know that the command I am trying to execute works
Code:
get-wmiobject win32_service -comp CORP-IT-VDI-03 | Group Startname -NoElement | Sort Count
My machine is joined to the domain and I am logged in under Domain Admin credentials. There are VMs CORP-IT-VDI-01 to 09 (nine in total). I've used a form of this script where it checks for RDP session. Using https://technet.microsoft.com/en-us/library/ff730958.aspx I took the basic fundamental of executing a command through a list of servers + the script I already had and put the two together to result in this concoction.
 
You can't do "$Server + "`n`n""
I'm not even sure why that is in this particular script... `n is "new line", which even if you could add that to $Server, would only cause issues with further logic on that variable.
I could be overlooking things again though :p
 
I removed the $Server + "`n`n" bit and that resolved half the errors.

Code:
_________________________________________________________________________________________________________________________
PS C:\Temp\testps> .\testps2.ps1
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Temp\testps\testps2.ps1:8 char:45
+ ForEach ($Server in $Servers) {get-wmiobject <<<<  win32_service -comp $Server | Group Startname -NoElement | Sort Count}
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
 

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Guess I'll have to look into the following links

http://tekrecipes.com/2014/04/16/get-wmiobject-the-rpc-server-is-unavailable/

https://social.technet.microsoft.co...d-vice-versa-access?forum=winserverpowershell
 
Last edited:
Good ol RPC unavailable...
Check:
Windows Firewall (Windows Management Instrumentation (WMI-In) rule specifically should be allowed)

These services:
Remote Access Auto Connection Manager
Remote Access Connection Manager
Remote Procedure Call (RPC)
Remote Procedure Call (RPC)
Locator Remote Registry

This regkey:
HKLM\Software\Microsoft\OLE, value: EnableDCOM -- value should be "Y"

Those are just some of the possibilities...
 
Aha, figured it out.

When it would output $Server, it would output the value of the distinguishedName attribute. I had to add this to the script:
Code:
 | select-object -expandproperty name

Here is the PowerShell script now:
Code:
# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory

# Query Active Directory for computers running a Server operating system
$Servers = Get-ADComputer -Filter {Name -like "corp-it-tech-*"} | select-object -expandproperty name

# Loop through the list to query each server for login sessions
ForEach ($Server in $Servers) {Write-Host "$Server" | get-wmiobject win32_service -comp $Server | Group Startname -NoElement | Sort Count | Format-Table }

The next thing I want to do but need direction for is that I would like to output this into a CSV file. Not only that, but I want to add a column with the value of $Server. This way we could execute the PowerShell script alone to get a single properly delimited CSV of whatever search criteria we configure the script for.

Right now, the output looks like this:
PS U:\> C:\Temp\testps\testps2.ps1
CORP-IT-TECH-01

Count Name
----- ----
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
106 localSystem


CORP-IT-TECH-02

Count Name
----- ----
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
107 localSystem


CORP-IT-TECH-03

Count Name
----- ----
1 COMPANYABC\jdoe
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
113 localSystem


CORP-IT-TECH-04

Count Name
----- ----
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
106 localSystem


CORP-IT-TECH-05

Count Name
----- ----
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
106 localSystem


CORP-IT-TECH-06

Count Name
----- ----
24 NT AUTHORITY\NetworkSe...
54 NT AUTHORITY\LocalService
105 localSystem

The "Write-Host "$Server" | " bit in the script is temporary. How do I output this to CSV and add $Server as the values for a third, presently non-existent column?

I've tried a few things but wasn't successful :\
 
You are in need of some major PowerShell assistance.
Code:
# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory

# Query Active Directory for computers running a Server operating system
$Servers = (Get-ADComputer -Filter {Name -like "corp-it-tech-*"}).Name

# Loop through the list to query each server for login sessions
ForEach ($Server in $Servers) {get-wmiobject win32_service -comp $Server | Group Startname -NoElement | Select-Object -Property @{'l'='ComputerName';e={$Server}},Count,Name } | Out-Csv -Path report file.csv -NoTypeInformation

The biggest question is what are you trying to query on each server? That WMI query makes no sense. Are you trying to find any non built-in service accounts?
 
Are you trying to find any non built-in service accounts?
Yep.

Genius consultants from the past two years who used their own credentials for mission critical services. Must find out where accounts are being used for services, too many VMs to do by hand.
 
Yep.

Genius consultants from the past two years who used their own credentials for mission critical services. Must find out where accounts are being used for services, too many VMs to do by hand.

Just PM'ed you a script that'll do everything you need.
 
Back
Top