Created
May 30, 2013 12:04
-
-
Save Iristyle/5677372 to your computer and use it in GitHub Desktop.
Turn a PSCustomObject into a standard hash
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 a PSCustomObject that may be returned over WinRM to a | |
standard Hashtable | |
.Description | |
.Parameter PSObject | |
.Example | |
#> | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory=$true)] | |
[PSCustomObject] | |
[AllowNull()] | |
$PSObject | |
) | |
$hash = @{} | |
$PSObject | Get-Member -MemberType NoteProperty | Select -First 1 Name | |
% { | |
$name = [string]$_ | |
$value = $PSObject.$name | |
Write-Host "Storing property $name and value $value" | |
$hash.$name = $value | |
#if ($_ -is [PSCustomObject]) | |
#{ $hash."$($_.Name)" = ConvertTo-Hashtable $_.Value } | |
} | |
return $hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment