Allow casting of psobject or object to hashtable - by Stephen Mills

Status : 

 


5
1
Sign in
to vote
ID 679841 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 7/18/2011 4:09:07 PM
Access Restriction Public

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".
Sign in to post a comment.