14
14
# -LicenseType [license_type_value] (Specific LT value)
15
15
# -All (Optional. Set the new license type value only if undefined)
16
16
#
17
+ # The script uses a function ConvertTo-HashTable that was created by Adam Bertram (@adam-bertram).
18
+ # The function was originally published in this blog: https://4sysops.com/archives/convert-json-to-a-powershell-hash-table/
19
+ # and used here with the author's permission.
20
+ #
17
21
18
22
param (
19
23
[Parameter (Mandatory = $false )]
@@ -55,7 +59,7 @@ function CheckModule ($m) {
55
59
}
56
60
}
57
61
58
- function ObjectToHashtable {
62
+ function ConvertTo-Hashtable {
59
63
[CmdletBinding ()]
60
64
[OutputType (' hashtable' )]
61
65
param (
@@ -74,7 +78,7 @@ function ObjectToHashtable {
74
78
if ($InputObject -is [System.Collections.IEnumerable ] -and $InputObject -isnot [string ]) {
75
79
$collection = @ (
76
80
foreach ($object in $InputObject ) {
77
- ObjectToHashtable - InputObject $object
81
+ ConvertTo-Hashtable - InputObject $object
78
82
}
79
83
)
80
84
# # Return the array but don't enumerate it because the object may be pretty complex
@@ -83,7 +87,7 @@ function ObjectToHashtable {
83
87
# # If the object has properties that need enumeration, cxonvert it to its own hash table and return it
84
88
$hash = @ {}
85
89
foreach ($property in $InputObject.PSObject.Properties ) {
86
- $hash [$property.Name ] = ObjectToHashtable - InputObject $property.Value
90
+ $hash [$property.Name ] = ConvertTo-Hashtable - InputObject $property.Value
87
91
}
88
92
$hash
89
93
} else {
@@ -160,7 +164,7 @@ foreach ($sub in $subscriptions){
160
164
}
161
165
162
166
$settings = @ {}
163
- $settings = $r.properties.settings | ConvertTo-Json | ConvertFrom-Json | ObjectToHashtable
167
+ $settings = $r.properties.settings | ConvertTo-Json | ConvertFrom-Json | ConvertTo-Hashtable
164
168
165
169
if ($settings.ContainsKey (" LicenseType" )) {
166
170
if ($All ) {
@@ -173,7 +177,7 @@ foreach ($sub in $subscriptions){
173
177
} else {
174
178
$settings [" LicenseType" ] = $LicenseType
175
179
Write-Host " Resource group: [$ ( $r.resourceGroup ) ] Connected machine: [$ ( $r.MachineName ) ] : License type: [$ ( $settings [" LicenseType" ]) ]"
176
- Set-AzConnectedMachineExtension @setId - Settings $settings
180
+ Set-AzConnectedMachineExtension @setId - Settings $settings | Out-Null
177
181
}
178
182
}
179
183
}
0 commit comments