PowerShell Objects

Don't try to understand it all if you are a beginner, just want you to be aware of these concepts.

PowerShell Objects can be a great help when handling data. I usually use these to store information and save it to an array for later use of export to a CSV file for reporting. Below is a older version of creating a PowerShell object that works on PowerShell 2.0 versions since some of my servers are still 2008 R2 and don’t have the newer PowerShell installed. If you follow it through you see the creation of the object and assigned values. The $X is an array and += tells the array to add to the array and not overwrite and current values stored in the Array.

In the bottom half you can see how to access the output using object oriented programming using the period and then the named property of the object.

PSObject PowerShell


A newer style of creating a PSObject and populating with data is displayed in image below.

PSCustom Object PowerShell

Resulting Output:

PowerShell Results