Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


windows:scripting:psobject

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

windows:scripting:psobject [2017/08/10 13:00] (current)
Line 1: Line 1:
 +====== Storing data in PSobject ======
 +===== Single line of data =====
 +<code powershell |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
 +</​code>​
 +Outputs
 +<​code>​
 +Manufacturer Model          SystemSKUNumber Serial Number
 +------------ -----          --------------- -------------
 +HP           ​ProBook 650 G3 98DJ#​23545 ​     KJ9FA323R3
 +</​code>​
 +
 +===== Multipe line of data =====
 +<code powershell |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
 +</​code>​
 +Outputs
 +<​code>​
 +Username ​           Screensaver
 +-------- ​           -----------
 +NT AUTHORITY\SYSTEM ​      False
 +VERSO\localuser ​          False
 +.DEFAULT ​                 False
 +</​code>​
 +
 +
 +{{tag>​Powershell}}
  
windows/scripting/psobject.txt · Last modified: 2017/08/10 13:00 (external edit)