PSCustomObject Using Select-Object

Just a tip #11

A traditional way of creating a PSCustomObject is as follows…

$Emp = [pscustomobject] @{
  Name = ''
  Department = ''
  Designation = ''
}

$Emp

Output:

Name Department Designation
---- ---------- -----------

Check the object type

C:\> $Emp.GetType().Name

Output:

PSCustomObject

And using Select-Object it is quite simple…

$Emp = '' | Select-Object -Property Name, Department,  Designation
$Emp

Output:

Name Department Designation
---- ---------- -----------

Check the object type

C:\> $Emp.GetType().Name

Output:

PSCustomObject

Share it on     |   |   |   | 
  Prev:  

ArgumentCompleter vs ValidateSet and Register-ArgumentCompleter

  :Next  

List and select in PowerShell console

comments powered by Disqus