Information Technology Reference
In-Depth Information
General information can be gained by simply entering the cmdlet and reviewing the output.
The default output provided has been programmed into PowerCLI to return the most com-
monly wanted properties of the given object. For instance, running the Get-VM cmdlet will
return all of the VMs in the inventory with the attributes VM name, power state, number of
CPUs, and memory (MB). You can specify which information you want to see using the Select-
Object cmdlet in the pipeline as follows:
Get-VM | Select-Object Name, PowerState
If you would like to see all information associated with all of the VMs, then you could run
the following one-liner with the second option demonstrating the very common Select-Object
alias Select:
Get-VM | Select-Object *
OR
Get-VM | Select *
We recommend outputting that to a CSV or text i le because it's likely to i ll up the screen
quickly. You can do that by piping to the Export-CSV cmdlet:
Get-VM | Select * | Export-CSV -Path C:\Test\VMs.csv -NoTypeInformation
We mentioned previously that you can get more detailed information about objects. Using
Select * gives you a full output of all property values, but there is an easier way to identify
what properties are available. Using the Get-Member cmdlet, you can get a full listing of avail-
able properties and methods of a particular object type. Try one of the following where the sec-
ond option uses GM, the shortened alias for Get-Member:
Get-VM | Get-Member
OR
Get-VM | GM
We have one i nal tip before moving on to other important PowerShell terms. If you have a
large inventory and want things to run faster while you learn, use the capability in the Select
-Object cmdlet to select only the i rst couple of returned objects. The following one-liner will
return the i rst three VM objects in your inventory:
Get-VM | Select -First 3
We'll go over more functionality with objects, but this should give you a taste of how simple
it is to select properties that you're interested in and a better understanding of the structure of
objects in PowerShell/PowerCLI.
Var i ables
Variables are not unique to PowerShell; they are used in many programming and scripting lan-
guages. In PowerShell, variables begin with a $ followed by alphanumeric characters. There are
both global and user-dei ned variables, and we'll touch on examples of each.
The easiest way to think of a variable is as an empty container where we can store objects
within PowerShell. Most common use cases for variables are to collect results of a script or to
Search WWH ::




Custom Search