Skip to content

Instantly share code, notes, and snippets.

@kpatnayakuni
Last active November 26, 2019 15:23
Show Gist options
  • Select an option

  • Save kpatnayakuni/8af168af4dabfebc1bf6cc4df50f6d96 to your computer and use it in GitHub Desktop.

Select an option

Save kpatnayakuni/8af168af4dabfebc1bf6cc4df50f6d96 to your computer and use it in GitHub Desktop.
Converts Object properties into HashTable
# Converts Object properties to HashTable.
Function Convert-ObjectToHashTable
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[pscustomobject] $Object
)
$HashTable = @{}
$ObjectMembers = Get-Member -InputObject $Object -MemberType *Property
foreach ($Member in $ObjectMembers)
{
$HashTable.$($Member.Name) = $Object.$($Member.Name)
}
return $HashTable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment