Sunday, 8 November 2015

Function to Display all PS Object Properties and their Values

A simple function to display all the properties of a PowerShell object and its values!

FUNCTION Display-AllProperties{
  Param($ObjectIn,[Switch]$Display)
  [System.Array]$Properties = @()
  ($ObjectIn | gm) | Foreach{ If ($_.MemberType -eq "Property"){ $Properties += $_.Name } }
  [System.Object]$Output = @{}
  [Int]$Index = 1
  Foreach ($Object in $ObjectIn){
    [System.Object]$Output.$Index = @{}
    $Properties | Foreach{
      $Output.$Index.$_ = $Object.$_
      If($Display){ Write-Host ("$_ = " + [String]($Object.$_)) }         
    }
    If($Display){ Write-Host }
    $Index ++
  }
  If(!$Display){ $Output }
}



No comments:

Post a Comment