14 lines
996 B
PowerShell

# Create a reference to the CIM_ComputerSystem instance.
$computerSystemRef = $wsmanConnectionObject.NewReference("SELECT * FROM CIM_ComputerSystem WHERE Name='ManagedSystem'")
$associatedPowerManagementRef = $wsmanConnectionObject.NewReference("CIM_AssociatedPowerManagementService")
$associatedPowerManagementRef.AddSelector("UserOfService", $computerSystemRef)
# Traverse to the CIM_AssociatedPowerManagementService instances that are connected to CIM_ComputerSystem instance.
foreach($associatedPowerManagementItem in $associatedPowerManagementRef.Enumerate("http://schemas.dmtf.org/wbem/wsman/1/wsman/SelectorFilter", $null))
{
# For each instance, check if it is associated to the CIM_PowerManagementService instance.
if($associatedPowerManagementItem.Object.GetProperty("ServiceProvided").IsA("CIM_PowerManagementService"))
{
$associatedPowerManagementInstance = $associatedPowerManagementItem.Object
$powerState = $associatedPowerManagementInstance.GetProperty("PowerState")
}
}