Summary: Running a "get-wmiobject" on another computer works properly. But when I "invoke-command" "get-wmiobject", I get access denied.
Detail: I have a workstation (Computer-Central) at our central site, from which I run an inventory script. The inventory script loops through several "get-wmi" commands for each IP on all our remote sites. If I log onto Computer-Central as a domain admin, the script works properly.
I'm now at one of those remote sites. My current workstation is (Computer-SiteA). So I can't log into Computer-Central directly; I have to RDP in. The trouble is, the RDP session times out before the script finishes (it takes about 12 hours). So I can't RDP in, start the script, and walk away. For various reasons, making a Scheduled Task is also out.
Powershell Remoting is enabled. I logged onto Computer-SiteA with my domain admin account and ran the following command:
invoke-command -computername Computer-Central {dir c:}
This worked properly. So I kicked off the inventory script with the following command (again, run as domain admin on Computer-SiteA):
invoke-command -computername Computer-Central -filepath c:\inventory.ps1
The script started and ran overnight. But the get-wmi commands all produced "Access Denied" errors. I RDP'd into Computer-Central and ran the following command:
get-wmiobject -class win32_computersystem -property name -computername Computer-SiteB
This worked properly. I got the WMI information back.
Then I logged onto Computer-SiteA and ran the following command:
invoke-command -computername Computer-Central {get-wmiobject -class win32_computersystem -property name -computername Computer-SiteB}
This failed with "Access Denied." I logged on as Domain Admin and even did a "Run As Different User" to make sure the PS console was open as my domain admin account.
I'm very confused by this. "Invoke-Command" should start the Powershell.exe process on the remote system with the credentials I've used on the local PC. The "get-wmiobject" command should pass the WMI query from the remote PC to the target PC, again with the same credentials. But that doesn't seem to be the case.
Any ideas?
EDIT: I ran this command to make Computer-Central query itself.
invoke-command -computername Computer-Central {get-wmiobject -class win32_computersystem -property name -computername Computer-Central}
That worked. If I invoke "get-wmiobject" on the remote system targeting itself, it works. If I invoke "get-wmiobject" on the remote system targeting a third system, it fails. I hope this helps.