Created
June 23, 2017 08:59
-
-
Save turboBasic/bbc3cdf6937fce2d036665b55ec48477 to your computer and use it in GitHub Desktop.
ConvertTo-Hashtable: Powershell utility function which converts psCustomObject to HashTable for betters seeking and iteration
This file contains hidden or 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 ConvertTo-Hashtable { | |
<# | |
.SYNOPSIS | |
Converts PsCustomObject type to Hashtable. Takes pipeline input and common arguments | |
.DESCRIPTION | |
Converts PsCustomObject type to Hashtable. Takes pipeline input, common arguments, | |
array arguments for bulk processing | |
#> | |
[CMDLETBINDING()] PARAM( | |
[PARAMETER( Position=0, | |
Mandatory, | |
ValueFromPipeline, | |
ValueFromPipelineByPropertyName )] | |
[ALIAS( 'CustomObject', | |
'psCustomObject', | |
'psObject' )] | |
[psCustomObject[]] $Object | |
) | |
BEGIN { } | |
PROCESS { | |
foreach ($_object in $Object) { | |
$output = @{ } | |
$_object | Get-Member -MemberType *Property | % { | |
$output.($_.name) = $_object.($_.name) | |
} | |
$output | |
} | |
} | |
END { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment