Progressing through the guide we have a variation on our previous script – this time we want to retrieve information about the operating system
Get-WmiObject -Class Win32_OperatingSystem | Select Name, Caption, CurrentTimeZone,
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.