Last active
August 19, 2016 10:31
-
-
Save gravejester/4c8906668966fcef703cb6e980e2b6fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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