@@ -635,37 +635,37 @@ function Remove-EndpointSecrets {
635635
636636function Disconnect-AzureAndClearContext {
637637 [CmdletBinding ()]
638- param ()
638+ param (
639+ [string ]$authScheme = ' ServicePrincipal'
640+ )
639641
640642 try {
641- Write-Verbose " Trying to disconnect from Azure and clear context"
643+ if ($authScheme -eq ' ServicePrincipal' ) {
644+ Write-Verbose " Trying to disconnect from Azure and clear context"
642645
643- if (Get-Command - Name " Disconnect-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
644- Write-Host " ##[command]Disconnect-AzureRmAccount"
645- Disconnect-AzureRmAccount
646- }
647- elseif (Get-Command - Name " Remove-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
648- Write-Host " ##[command]Remove-AzureRmAccount"
649- Remove-AzureRmAccount
650- }
651- elseif (Get-Command - Name " Logout-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
652- Write-Host " ##[command]Logout-AzureRmAccount"
653- Logout- AzureRmAccount
654- }
655- else {
656- $noCommandMessage = " Unable to find a command to log out of Azure"
657- Write-Host " ##vso[task.logissue type=warning;]$noCommandMessage "
658- }
646+ if (Get-Command - Name " Disconnect-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
647+ Write-Host " ##[command]Disconnect-AzureRmAccount"
648+ $null = Disconnect-AzureRmAccount
649+ }
650+ elseif (Get-Command - Name " Remove-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
651+ Write-Host " ##[command]Remove-AzureRmAccount"
652+ $null = Remove-AzureRmAccount
653+ }
654+ elseif (Get-Command - Name " Logout-AzureRmAccount" - ErrorAction " SilentlyContinue" ) {
655+ Write-Host " ##[command]Logout-AzureRmAccount"
656+ $null = Logout- AzureRmAccount
657+ }
659658
660- if (Get-Command - Name " Clear-AzureRmContext" - ErrorAction " SilentlyContinue" ) {
661- Write-Host " ##[command]Clear-AzureRmContext -Scope Process"
662- $null = Clear-AzureRmContext - Scope Process
663- Write-Host " ##[command]Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue"
664- $null = Clear-AzureRmContext - Scope CurrentUser - Force - ErrorAction SilentlyContinue
659+ if (Get-Command - Name " Clear-AzureRmContext" - ErrorAction " SilentlyContinue" ) {
660+ Write-Host " ##[command]Clear-AzureRmContext -Scope Process"
661+ $null = Clear-AzureRmContext - Scope Process
662+ Write-Host " ##[command]Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue"
663+ $null = Clear-AzureRmContext - Scope CurrentUser - Force - ErrorAction SilentlyContinue
664+ }
665665 }
666666 } catch {
667- $error = $_.Exception.Message
668- Write-Verbose " Unable to disconnect and clear context: $error "
669- Write-Host " ##vso[task.logissue type=warning;]$error "
667+ $message = $_.Exception.Message
668+ Write-Verbose " Unable to disconnect and clear context: $message "
669+ Write-Host " ##vso[task.logissue type=warning;]$message "
670670 }
671671}
0 commit comments