Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created May 30, 2013 12:04
Show Gist options
  • Save Iristyle/5677372 to your computer and use it in GitHub Desktop.
Save Iristyle/5677372 to your computer and use it in GitHub Desktop.
Turn a PSCustomObject into a standard hash
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