AdminPasswordStatus # translate raw value to friendly text # this yields empty information because PowerShell uses the # data type (signed 32-bit integers) # while WMI sends the numeric value # using the data type (unsigned 16-bit integers) # so PowerShell cannot find the key in its # hashtable and returns nothing: $friendlyName = $AdminPasswordStatus_map # output value "Admin Password Status: $friendlyName " # example returns the current admin password status # this example contains an error and returns "nothing" # this hashtable translates the codes to # meaningful friendly text: $AdminPasswordStatus_map = 0 = 'Disabled' 1 = 'Enabled' 2 = 'Not Implemented' 3 = 'Unknown' } # get instance of Win32_ComputerSystem # representing the current computer: $computer = Get-CimInstance -Class Win32_ComputerSystem # query the property AdminPasswordStatus # it yields a numeric value $rawValue = $computer. The reference also returns a PowerShell hashtable to translate the values into text: The information uses the data type (unsigned 16-bit integer). When you look up this property, you learn that this property returns the hardware security settings for the administrator password status. WMI information is often coded and uses numeric values instead of meaningful text.įor example, the WMI class Win32_ComputerSystem contains the property AdminPasswordStatus. Here is an example that illustrates the problem and ways to work around it: Translating WMI Codes to Friendly Text Make sure you convert the received WMI data to the corresponding PowerShell data types where appropriate. When PowerShell processes data received from WMI, it may not recognize the WMI data types.Make sure you convert your arguments to the exact data types the WMI method expects to receive. When you call WMI methods and send arguments that use PowerShell data types, WMI may not interpret the data correctly. ![]() Both PowerShell and WMI can understand each other only when they understand how to interpret the data. ![]() When you read data from WMI and output it in reports, you do not need to care much about data types because numbers look the same when outputted as text.Īs soon as you process WMI output, though, correct data types matter. WMI uses its own data types that differ from the data types used by PowerShell.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |