Networked WMI Operations with PowerShell CIM
How do I query WMI on an authorized remote PC?
Create a CimSession to an explicitly authorized computer, run read-only queries, and remove the session when finished.
Query an authorized remote Windows computer through a CIM session.
Follow the steps in order and stop if the screen or target does not match what is described. Use administrator access only when the task requires it.
Prepare managed remoting
The target must be authorized, reachable, and configured for Windows Remote Management with appropriate firewall and authentication policy.
Create a session
Use an explicit computer name. PowerShell can securely prompt for credentials when required.
$session = New-CimSession -ComputerName PC-NAMERun a read-only query
Pass the session to Get-CimInstance.
Get-CimInstance -CimSession $session -ClassName Win32_OperatingSystem | Select-Object Caption, Version, LastBootUpTimeQuery disk free space
Filter to local disks and select explicit properties.
Get-CimInstance -CimSession $session -ClassName Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID, Size, FreeSpaceRemove the session
Always close the session when the task is complete.
Remove-CimSession -CimSession $sessionDo not weaken authentication
Do not disable certificate checks, expose WinRM publicly, or add wildcard TrustedHosts entries to make a failed connection work.