1+ # Requires -Version 4.0
12function ConvertTo-HashString
23{
34<#
@@ -21,10 +22,7 @@ function ConvertTo-HashString
2122 $hashObject | ConvertTo-HashString
2223
2324 This will convert the hashtable to the following string
24- @{
25- Name = "Tore"
26- Goal = "Rule the World"
27- }
25+ @{Name = "Tore";Goal = "Rule the World";}
2826
2927. INPUTS
3028 Hashtable
@@ -41,29 +39,15 @@ function ConvertTo-HashString
4139Param (
4240 [Parameter (ValueFromPipeLine )]
4341 $InputObject
44- ,
45- [string ]$PreSpacing
4642)
4743Begin
4844{
4945 $f = $MyInvocation.InvocationName
5046 Write-Verbose - Message " $f - START"
51- $newLine = [environment ]::NewLine
52-
53- if ($PreSpacing )
54- {
55- $endspaceCount = $PreSpacing.Length - 4
56- if ($endspaceCount -lt 0 ){$endspaceCount = 0 }
57- $endspace = " " * $endspaceCount
58- $beginSpace = " " * $endspaceCount
59- }
6047}
6148Process
6249{
6350 $out = " @{"
64-
65- $out = $out # + $newLine
66- $preSpace = $PreSpacing
6751
6852 if (-not $InputObject -or $InputObject.keys.count -eq 0 ) {return " @{}" }
6953
@@ -112,7 +96,7 @@ Process
11296 $DisplayKey = $null
11397 }
11498
115- $out += " $PreSpacing$ key = "
99+ $out += " $key = "
116100
117101 switch ($mode )
118102 {
@@ -129,26 +113,26 @@ Process
129113 $ticks = $value.Ticks
130114 $out += " New-Date $ticks ;"
131115 }
132- else {
133- $out += ' " ' + $value + ' "; ' # + $newLine
134- }
135-
116+ else
117+ {
118+ $out += ' " ' + $value + ' "; '
119+ }
136120 }
137121
138122 ' hashtable'
139123 {
140- $stringValue = ConvertTo-HashString - InputObject $value # -PreSpacing "$PreSpacing "
141- $out += $stringValue + " ;" # + $newLine
124+ $stringValue = ConvertTo-HashString - InputObject $value
125+ $out += $stringValue + " ;"
142126 }
143127
144128 ' HashTableValue'
145129 {
146130 $stringValue = " "
147131 foreach ($arrayHash in $value )
148132 {
149- $hashString = ConvertTo-HashString - InputObject $arrayHash # -PreSpacing "$PreSpacing "
133+ $hashString = ConvertTo-HashString - InputObject $arrayHash
150134 $hash = " $hashString "
151- $hash = " $hash ," # + $newLine
135+ $hash = " $hash ,"
152136 $stringValue += $hash
153137 }
154138 $separatorIndex = $stringValue.LastIndexOf (" ," )
@@ -162,16 +146,19 @@ Process
162146 {
163147 $out += ($value -join " ," ) + " ;"
164148 }
165- else {
166- $out += ' "' + ($value -join ' ","' ) + ' ";' # + $newLine
149+ else
150+ {
151+ $out += ' "' + ($value -join ' ","' ) + ' ";'
167152 }
168153
169154 }
170155
171- Default {}
156+ default
157+ {
158+ Write-Error - Message " Invalid mode in funtion $f "
159+ }
172160 }
173- }
174- # $out += "$endspace}"
161+ }
175162 $out += " }"
176163 $out
177164}
0 commit comments