W2KSG: Operating System Info

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 :

 

Read the complete post at http://richardsiddaway.spaces.live.com/Blog/cns!43CFA46A74CF3E96!1762.entry

Published Fri, Sep 19 2008 14:14 by Richard Siddaway's Blog
Filed under: