Converting Hash Tables to Objects
Hash Tables are convenient but are not true objects. This is bad because you are unable to output the hash content to formatting cmdlets or...
- Written By: ps1
- Last Updated: April 21, 2025
- 1 minute read
Hash Tables are convenient but are not true objects. This is bad because you are unable to output the hash content to formatting cmdlets or...
Hash Tables are convenient but are not true objects. This is bad because you are unable to output the hash content to formatting cmdlets or export cmdlets. With a short function, you can easily convert a Hash Table to an object, providing all the flexibility you need to forward the object to other cmdlets like Format-Table or Export-CSV:
function ConvertTo-Object($hashtable)
{
$object = New-Object PSObject
$hashtable.GetEnumerator() |
ForEach-Object { Add-Member -inputObject $object `
-memberType NoteProperty -name $_.Name -value $_.Value }
$object
}
$hash = @{Name='Tobias'=='Online'}
$hash
ConvertTo-Object $hash
Contact our sales team to get a personalized demo of our database management software for SQL Server!