Skip to content

Instantly share code, notes, and snippets.

@gravejester
Last active August 19, 2016 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravejester/4c8906668966fcef703cb6e980e2b6fa to your computer and use it in GitHub Desktop.
Save gravejester/4c8906668966fcef703cb6e980e2b6fa to your computer and use it in GitHub Desktop.
function Get-ObjectPropertyInfo {
#Requires -Version 3
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
$InputObject
)
$objectProperties = $InputObject | Get-Member -MemberType '*Property*'
Write-Verbose -Message "Object have $($objectProperties.Count) properties."
foreach ($item in $InputObject) {
for ($i = 0; $i -le ($objectProperties.Count); $i++) {
# Property Name
$thisPropertyName = ($objectProperties[$i].Name)
# Property Value
$thisPropertyValue = $item.($objectProperties[$i].Name)
# Property Type
try {
$thisPropertyType = $item.($objectProperties[$i].Name).GetType().BaseType.Name
if (($thisPropertyType -eq 'Object') -or ($thisPropertyType -eq 'ValueType')) {
$thisPropertyType = $item.($objectProperties[$i].Name).GetType().Name
}
}
catch {
$thisPropertyType = $null
}
Write-Output -InputObject ([PSCustomObject] [Ordered] @{
Name = $thisPropertyName
Value = $thisPropertyValue
Type = $thisPropertyType
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment