Skip to content

Commit

Permalink
Updated MPSXM to 3.28.2
Browse files Browse the repository at this point in the history
  • Loading branch information
texhex committed Jul 23, 2018
1 parent 1cc7676 commit 4364867
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions MPSXM.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Michael's PowerShell eXtension Module
# Version 3.28.1
# Version 3.28.2
# https://github.com/texhex/MPSXM
#
# Copyright © 2010-2018 Michael 'Tex' Hex
Expand Down Expand Up @@ -814,26 +814,40 @@ Function Read-StringHashtable()
Key2==Value2
...
#>
{

{
#.SYNOPSIS
#Reads a hashtable from a file where the Key-Value pairs are stored as Key==Value
#
#.PARAMETER File
#The file to read the hashtable from
#
#.PARAMETER AsOrderedDictionary
#If the order of the setting matter, use this parameter to return an OrderedDictionary where the order of the keys is exactly as they are in the file
#
#.OUTPUTS
#Hashtable

[OutputType([Hashtable])]
param(
[Parameter(Mandatory = $True, ValueFromPipeline = $True)]
[string]$File
[string]$File,

[Parameter(Mandatory = $False)]
[switch]$AsOrderedDictionary = $False
)

$result = @{}
write-verbose "Reading hashtable from $file"

$result = $null
if ( -not $AsOrderedDictionary )
{
$result = @{}
}
else
{
$result = [Ordered]@{}
}


if ( Test-Path $file )
{
$data = Get-Content $file -Raw
Expand Down Expand Up @@ -864,12 +878,22 @@ Function Read-StringHashtable()
else
{
$name = $setting[0].Trim()
$value = $setting[1].Trim()
$value = $setting[1].Trim()
$nameAlreadyExists = $false

#I'm unsure if this information is of any use
#write-verbose "Key-Value pair found: [$name] : [$value]"

if ( $result.ContainsKey($name) )
if ( -not $AsOrderedDictionary )
{
$nameAlreadyExists=$result.ContainsKey($name)
}
else
{
$nameAlreadyExists=$result.Contains($name)
}

if ( $nameAlreadyExists )
{
throw New-Exception -InvalidOperation "Can not add key [$name] (Value: $value) because a key of this name already exists"
}
Expand Down

0 comments on commit 4364867

Please sign in to comment.