Table of Contents

Storing data in PSobject

Single line of data

|Single line
$ComputerInfo = New-Object -TypeName PSObject
$ComputerInfo | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value "HP"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name "Model" -Value "ProBook 650 G3"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name "SystemSKUNumber" -Value "98DJ#23545"
$ComputerInfo | Add-Member -MemberType NoteProperty -Name "Serial Number" -Value "KJ9FA323R3"
$ComputerInfo | Format-Table

Outputs

Manufacturer Model          SystemSKUNumber Serial Number
------------ -----          --------------- -------------
HP           ProBook 650 G3 98DJ#23545      KJ9FA323R3

Multipe line of data

|Multi line
$DataSet1 = Get-WmiObject -Class Win32_Desktop -ErrorAction Stop| select name,ScreenSaverActive
$UserInfo = @()
ForEach ($Item in $DataSet1) {
    $tmpUserInfo = New-Object -TypeName PSObject
    $tmpUserInfo | Add-Member -MemberType NoteProperty -Name "Username" -Value $Item.Name
    $tmpUserInfo | Add-Member -MemberType NoteProperty -Name "Screensaver" -Value $Item.ScreenSaverActive
    $UserInfo += $tmpUserInfo
}
$UserInfo | Format-Table

Outputs

Username            Screensaver
--------            -----------
NT AUTHORITY\SYSTEM       False
VERSO\localuser           False
.DEFAULT                  False