From a616407c1b164d16f5bbe12241e32e7f8bb01615 Mon Sep 17 00:00:00 2001 From: Severin Leonhardt Date: Wed, 13 Sep 2017 08:56:03 +0200 Subject: [PATCH] Fix accessing dictionary keys When the dictionary contains an entry with the key 'keys' accessing the property `.keys` will not return the keys of the dictionary but the value associated with the key 'keys'. --- Functions/Out-IniFile.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Functions/Out-IniFile.ps1 b/Functions/Out-IniFile.ps1 index b40e84e..826e0a2 100644 --- a/Functions/Out-IniFile.ps1 +++ b/Functions/Out-IniFile.ps1 @@ -160,11 +160,11 @@ Function Out-IniFile { Process { - if (!($InputObject.keys)) + if (!($InputObject.get_keys())) { Write-Warning ("No data found in '{0}'." -f $FilePath) } - Foreach ($key in $InputObject.keys) + Foreach ($key in $InputObject.get_keys()) { if ($key -match "^Comment\d+") { Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing comment: $key" @@ -203,7 +203,7 @@ Function Out-IniFile { if (!(Test-Path $outFile.FullName)) {Throw "Could not create File"} Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing to file: $Filepath" - foreach ($i in $InputObject.keys) + foreach ($i in $InputObject.get_keys()) { if (!($InputObject[$i].GetType().GetInterface('IDictionary'))) {