Skip to content

Commit fc499e3

Browse files
committed
Update Get-CIPPAuthentication.ps1
1 parent 80a1931 commit fc499e3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ function Get-CIPPAuthentication {
1919
}
2020
}
2121
} else {
22+
Write-Information 'Connecting to Azure'
2223
Connect-AzAccount -Identity
2324
$SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1
24-
$null = Set-AzContext -SubscriptionId $SubscriptionId
25+
try {
26+
$Context = Get-AzContext
27+
if ($Context.Subscription.Id -ne $SubscriptionId) {
28+
Write-Information "Setting context to subscription $SubscriptionId"
29+
$null = Set-AzContext -SubscriptionId $SubscriptionId
30+
}
31+
} catch {
32+
Write-Information "ERROR: Could not set context to subscription $SubscriptionId."
33+
}
34+
2535
$keyvaultname = ($env:WEBSITE_DEPLOYMENT_ID -split '-')[0]
2636
$Variables | ForEach-Object {
2737
Set-Item -Path env:$_ -Value (Get-AzKeyVaultSecret -VaultName $keyvaultname -Name $_ -AsPlainText -ErrorAction Stop) -Force

0 commit comments

Comments
 (0)