This is an easy point of conversion. Anytime you used GetObject() or some other means of retrieving WMI information, just use the Get-Wmiobject cmdlet or its convenient alias, Gwmi, in PowerShell. However, notice that just running it with a class name won't return every property of the class by default:
PS C:\> gwmi win32_operatingsystem SystemDirectory : C:\WINDOWS\system32 Organization : SAPIEN Technologies, Inc. BuildNumber : 2600 RegisteredUser : Don Jones SerialNumber : 76487-338-1820253-22242 Version : 5.1.2600
Notice that this doesn't return every property for the class. Instead, the properties shown are defined by a special view within PowerShell. While you can update that view to list more properties, you can also use the -property parameter if there's a specific property you need:
PS C:\> gwmi win32_operatingsystem -property buildnumber BuildNumber : 2600 __GENUS : 2 __CLASS : Win32_OperatingSystem __SUPERCLASS : __DYNASTY : __RELPATH : __PROPERTY_COUNT : 1 __DERIVATION : {} __SERVER : __NAMESPACE : __PATH :
If necessary, you can assign that to a variable. However, notice that you get back a collection of multiple instances that can be referred to individually by number as shown here:
PS C:\> $obj = gwmi win32_logicaldisk PS C:\> $obj[0] DeviceID : A: DriveType : 2 ProviderName : FreeSpace : Size : VolumeName : PS C:\> $obj[1] DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 91841773568 Size : 153006624768 VolumeName :
If you just need a specific property from an instance:
PS C:\> $obj[1].DriveType 3
Run Help Gwmi to get a comprehensive list of parameters, or refer to Appendix A of this book.