Appendix A. PowerShell reference
This appendix supplies a number of templates, syntax formats, and other useful information that you can use when creating your PowerShell scripts.
A.1. Automatic variables
There are a large number of variables that PowerShell automatically creates. The list can be seen by using
Get-Help about_Automatic_Variables
Reviewing the contents of this help file is highly recommended.
A.2. Calculated fields
Use calculated fields to create new properties or to perform calculations:
Get-WmiObject -Class Win32_OperatingSystem | select @{Name="BootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}}
A.3. Flow syntax
The if and switch statements are used to control flow:
if (<condition>){ .. statements .. } elseif ...
Get PowerShell and WMI now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.