1414# -LicenseType [license_type_value] (Specific LT value)
1515# -All (Optional. Set the new license type value only if undefined)
1616#
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+ #
1721
1822param (
1923 [Parameter (Mandatory = $false )]
@@ -55,7 +59,7 @@ function CheckModule ($m) {
5559 }
5660}
5761
58- function ObjectToHashtable {
62+ function ConvertTo-Hashtable {
5963 [CmdletBinding ()]
6064 [OutputType (' hashtable' )]
6165 param (
@@ -74,7 +78,7 @@ function ObjectToHashtable {
7478 if ($InputObject -is [System.Collections.IEnumerable ] -and $InputObject -isnot [string ]) {
7579 $collection = @ (
7680 foreach ($object in $InputObject ) {
77- ObjectToHashtable - InputObject $object
81+ ConvertTo-Hashtable - InputObject $object
7882 }
7983 )
8084 # # Return the array but don't enumerate it because the object may be pretty complex
@@ -83,7 +87,7 @@ function ObjectToHashtable {
8387 # # If the object has properties that need enumeration, cxonvert it to its own hash table and return it
8488 $hash = @ {}
8589 foreach ($property in $InputObject.PSObject.Properties ) {
86- $hash [$property.Name ] = ObjectToHashtable - InputObject $property.Value
90+ $hash [$property.Name ] = ConvertTo-Hashtable - InputObject $property.Value
8791 }
8892 $hash
8993 } else {
@@ -160,7 +164,7 @@ foreach ($sub in $subscriptions){
160164 }
161165
162166 $settings = @ {}
163- $settings = $r.properties.settings | ConvertTo-Json | ConvertFrom-Json | ObjectToHashtable
167+ $settings = $r.properties.settings | ConvertTo-Json | ConvertFrom-Json | ConvertTo-Hashtable
164168
165169 if ($settings.ContainsKey (" LicenseType" )) {
166170 if ($All ) {
@@ -173,7 +177,7 @@ foreach ($sub in $subscriptions){
173177 } else {
174178 $settings [" LicenseType" ] = $LicenseType
175179 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
177181 }
178182 }
179183}
0 commit comments