Cerulean
[H]F Junkie
- Joined
- Jul 27, 2006
- Messages
- 9,476
run.bat
testps2.ps1
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:
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
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.
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