1313# -ResourceGroup [resource_goup] (Limit scope to a specific resoure group)
1414# -MachineName [machine_name] (Limit scope to a specific machine)
1515# -LicenseType [license_type_value] (Specific LT value)
16- # -All (Required. Set the new license type on all installed extensions.
16+ # -Force (Required. Set the new license type on all installed extensions.
1717# By default the value is set only if license type is undefined undefined)
1818#
1919# The script uses a function ConvertTo-HashTable that was created by Adam Bertram (@adam-bertram).
@@ -32,7 +32,7 @@ param (
3232 [ValidateSet (" PAYG" , " Paid" , " LicenseOnly" , IgnoreCase= $false )]
3333 [string ] $LicenseType ,
3434 [Parameter (Mandatory = $false )]
35- [boolean ] $All = $false
35+ [boolean ] $Force = $false
3636)
3737
3838function CheckModule ($m ) {
@@ -117,12 +117,14 @@ $requiredModules | Foreach-Object {CheckModule $_}
117117
118118# Subscriptions to scan
119119
120+ $tenantID = (Get-AzureADTenantDetail ).ObjectId
121+
120122if ($SubId -like " *.csv" ) {
121123 $subscriptions = Import-Csv $SubId
122124}elseif ($SubId -ne " " ){
123- $subscriptions = [PSCustomObject ]@ {SubscriptionId = $SubId } | Get-AzSubscription
125+ $subscriptions = [PSCustomObject ]@ {SubscriptionId = $SubId } | Get-AzSubscription - TenantID $tenantID
124126}else {
125- $subscriptions = Get-AzSubscription
127+ $subscriptions = Get-AzSubscription - TenantID $tenantID
126128}
127129
128130
@@ -135,7 +137,7 @@ foreach ($sub in $subscriptions){
135137 if ($sub.State -ne " Enabled" ) {continue }
136138
137139 try {
138- Set-AzContext - SubscriptionId $sub.Id
140+ Set-AzContext - SubscriptionId $sub.Id - Tenant $tenantID
139141 }catch {
140142 write-host " Invalid subscription: $ ( $sub.Id ) "
141143 {continue }
@@ -180,7 +182,7 @@ foreach ($sub in $subscriptions){
180182 $settings = $r.properties.settings | ConvertTo-Json | ConvertFrom-Json | ConvertTo-Hashtable
181183
182184 if ($settings.ContainsKey (" LicenseType" )) {
183- if ($All ) {
185+ if ($Force ) {
184186 if ($settings [" LicenseType" ] -ne $LicenseType ) {
185187 $settings [" LicenseType" ] = $LicenseType
186188 Write-Host " Resource group: [$ ( $r.resourceGroup ) ] Connected machine: [$ ( $r.MachineName ) ] : License type: [$ ( $settings [" LicenseType" ]) ]"
0 commit comments