Skip to content

Instantly share code, notes, and snippets.

@phatmandrake
Last active March 16, 2022 22:16
Show Gist options
  • Save phatmandrake/73e4dff326776a0a3f0c056ffbf5f9bf to your computer and use it in GitHub Desktop.
Save phatmandrake/73e4dff326776a0a3f0c056ffbf5f9bf to your computer and use it in GitHub Desktop.
Convert a PSCustomObject to a Dictionary/Hashtable
class PSHashTable : Collections.Generic.Dictionary[string, string]{
PSHashTable ([PSCustomObject]$Object) {
$Object.psobject.properties | ForEach-Object -Process {$this.add($_.name,$Object.($_.name))}
}
}
[HashTable][PSHashTable][PSCustomObject]@{Prop = "val"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment