Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created April 1, 2015 19:02
Show Gist options
  • Save adamdriscoll/d240dc21944b403feffd to your computer and use it in GitHub Desktop.
Save adamdriscoll/d240dc21944b403feffd to your computer and use it in GitHub Desktop.
Hashtable to Dictionary
function Dictionary
{
param([Type[]]$Type, [Hashtable]$Hashtable)
$KeyType = $Type[0]
$ValueType = $Type[1]
$Dictionary = New-Object -TypeName "System.Collections.Generic.Dictionary[$KeyType,$ValueType]"
$Hashtable.GetEnumerator() | % {
$Dictionary.Add($_.Key, $_.Value)
}
$Dictionary
}
Dictionary System.DayOfWeek, String @{
'Saturday' = "Caturday";
'Sunday' = "Funday";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment