Skip to content

Commit 6113d0a

Browse files
authored
Merge pull request #1104 from anosov1960/master
Added link to the function's author
2 parents 608e27c + 8095be5 commit 6113d0a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
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

1822
param (
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

Comments
 (0)