Skip to content

Commit dad1d59

Browse files
v2.30.0
1 parent 0f10717 commit dad1d59

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

PSScriptTools.psd1

0 Bytes
Binary file not shown.

PSScriptToolsManual.pdf

82 Bytes
Binary file not shown.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,4 +1832,4 @@ If you find this module useful, you might also want to look at my PowerShell too
18321832

18331833
Where possible these commands have been tested with PowerShell 7, but not every platform. If you encounter problems, have suggestions or other feedback, please post an [issue](https://github.com/jdhitsolutions/PSScriptTools/issues). It is assumed you will __not__ be running these commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
18341834

1835-
Last Updated *2020-09-29 12:53:26Z*
1835+
Last Updated *2020-10-02 19:51:46Z*

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog for PSScriptTools
22

3+
## v2.30.0
4+
5+
+ Fixed a bug in `Convert-HashtableToCode` when converting hashtables with nested hashtables. (Issue #91)
6+
+ Modified `Convert-HashtableToCode` to honor `-Inline` when processing nested hashtables.
7+
+ Updated help documentation for `Convert-HashtableToCode` to clarify the use of array values in a hashtable.
8+
39
## v2.29.0
410

511
+ Modified `Get-WindowsVersion` to not use remoting when connecting to the local computer. (Issue #90)

docs/Convert-HashtableToCode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Convert-HashtableToCode [-Hashtable] <Hashtable> [-Inline] [<CommonParameters>]
2828

2929
## DESCRIPTION
3030

31-
Use this command to convert a hashtable into its text or string equivalent.
31+
Use this command to convert a hashtable into its text or string equivalent. It is assumed that any array values contain items of the same type.
3232

3333
## EXAMPLES
3434

@@ -76,7 +76,7 @@ Accept wildcard characters: False
7676
7777
### -Indent
7878
79-
Specify the number of tabs to indent. You shouldn't need this parameter. It exists for situations where there are nested hashtables.
79+
Specify the number of tabs to indent. You shouldn't need to specify this parameter. It exists for situations where there are nested hashtables.
8080
8181
```yaml
8282
Type: Int32

en-us/PSScriptTools-help.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ CreatedOn BOVINE320</dev:code>
11091109
</maml:description>
11101110
</command:details>
11111111
<maml:description>
1112-
<maml:para>Use this command to convert a hashtable into its text or string equivalent.</maml:para>
1112+
<maml:para>Use this command to convert a hashtable into its text or string equivalent. It is assumed that any array values contain items of the same type.</maml:para>
11131113
</maml:description>
11141114
<command:syntax>
11151115
<command:syntaxItem>
@@ -1129,7 +1129,7 @@ CreatedOn BOVINE320</dev:code>
11291129
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="tab">
11301130
<maml:name>Indent</maml:name>
11311131
<maml:Description>
1132-
<maml:para>Specify the number of tabs to indent. You shouldn't need this parameter. It exists for situations where there are nested hashtables.</maml:para>
1132+
<maml:para>Specify the number of tabs to indent. You shouldn't need to specify this parameter. It exists for situations where there are nested hashtables.</maml:para>
11331133
</maml:Description>
11341134
<command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
11351135
<dev:type>
@@ -1182,7 +1182,7 @@ CreatedOn BOVINE320</dev:code>
11821182
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="tab">
11831183
<maml:name>Indent</maml:name>
11841184
<maml:Description>
1185-
<maml:para>Specify the number of tabs to indent. You shouldn't need this parameter. It exists for situations where there are nested hashtables.</maml:para>
1185+
<maml:para>Specify the number of tabs to indent. You shouldn't need to specify this parameter. It exists for situations where there are nested hashtables.</maml:para>
11861186
</maml:Description>
11871187
<command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
11881188
<dev:type>

functions/hashtableTools.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,28 @@ Function Convert-HashtableToCode {
154154
if ($_.value[0].Gettype().name -match "int|double") {
155155
$value = $_.value -join ','
156156
}
157+
elseif ($_.value[0].GetType().name -eq "Hashtable") {
158+
#10/2/2020 JDH need to process nested hashtables in an array (Issue #91)
159+
if ($inline) {
160+
$value = ($_.value | Convert-HashtableToCode -inline).trim() -join ","
161+
}
162+
else {
163+
$value = ($_.value | Convert-HashtableToCode).trim() -join ",`n"
164+
}
165+
}
157166
else {
158167
$value = "'{0}'" -f ($_.value -join "','")
159168
}
160169
}
161170
elseif ($_.value -is [hashtable]) {
162171
Write-Verbose "Creating nested entry"
163-
$nested = Convert-HashTableToCode $_.value -Indent $($indent + 1)
172+
#10/2/2020 JDH convert hashtables using current values
173+
if ($inline) {
174+
$nested = Convert-HashtableToCode $_.value -inline
175+
}
176+
else {
177+
$nested = Convert-HashTableToCode $_.value -Indent $($indent + 1)
178+
}
164179
$value = "$($nested)"
165180
}
166181
elseif ($_.value -is [scriptblock]) {
@@ -171,6 +186,7 @@ Function Convert-HashtableToCode {
171186
Write-Verbose "..defaulting as a string"
172187
$value = "'$($_.value)'"
173188
}
189+
174190
if ($inline) {
175191
$out += "$($_.key) = $value;"
176192
}

0 commit comments

Comments
 (0)