Home Dashboard Directory Help
Search

Allow casting of psobject or object to hashtable by Stephen Mills


Status: 

Active


4
1
Sign in
to vote
Type: Suggestion
ID: 679841
Opened: 7/18/2011 4:09:07 PM
Access Restriction: Public
0
Workaround(s)
view

Description

There are times when a hashtable can be more useful than a psobject. In those cases it would be very welcome to be able to easily convert psobjects to hashtables. One case is that you can add to hashtables together to have a new hashtable with the property of both of the other hashtables.

$a = New-Object PSObject -Property @{a=1;b=2;c=3}
[Hashtable]$a

This results in an error message that includes a hashtable of the values from the psobject. It's funny that it can't convert it at this point.
Cannot convert the "@{a=1; b=2; c=3}" value of type "System.Management.Automation.PSCustomObject" to type "System.Collections.Hashtable".
Details
Sign in to post a comment.
Sign in to post a workaround.