header image

W2KSG: Operating System Info

Posted by: | September 19, 2008 | No Comment |

Progressing through the guide we have a variation on our previous script – this time we want to retrieve information about the operating system

Listing 6.7

Get-WmiObject -Class Win32_OperatingSystem | Select Name, Caption, CurrentTimeZone,

@{Name=’LastBootUpTime’; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}},

@{Name=’LocalDateTime’; Expression={$_.ConvertToDateTime($_.LocalDateTime)}},

Locale, Manufacturer, OSType, Version, ServicePackMajorVersion, ServicePackMinorVersion, WindowsDirectory

We use Win32_OperatingSystem in Get-WmiObject and then a select as normal.  Most of the properties are straightforward but the LastBootUpTime and the LocalDateTime are held in WMI’s format rather than a more readable form. 

We can use a calculated expression as shown to perform the conversion.  Using a variation of a hashtable we define a name for the field and use a script block to define the expression used to calculate the value. As the object is coming down the pipeline we can use $_ to represent that object.


Share this post :


under: PowerShell and WMI