I am not able to make a WMI connection to any VM on Azure running windows OS. The same commands work perfectly well on my LAN and WAN to connect to any Windows machine.
For example
Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem -Impersonation 3 -ComputerName RemoteWinHost -Credential domain\username
Works fine and gets me the desired info from "RemoteWinHost". However, the same fails when I try to get for a Azure VM and gives me this error :
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem -Im ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Can someone please guide me on how to accomplish the WMI connection to Azure VM. The VM is not a part of my domain and for Credential I am using the hostname in place of the domain name (hostname\username). Also tried it without appending the hostname. Same result.
In most cases, it is the firewall. Check it and telnet the ports to make sure you can talk to them. I think the port should be TCP/UDP 135. You can try running the query from inside the target system to make sure of that.
Another thing you can try is the Invoke-Command
but it requires WinRM.
Invoke-Command -ScriptBlock {Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem} -Computer RemoteWinHost -Credential $credentialObject
User contributions licensed under CC BY-SA 3.0