Skip to content

Commit 53e8efa

Browse files
authored
fix for Az.accounts backward compatibility (#21121)
1 parent 000e8ee commit 53e8efa

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

Tasks/AzureFileCopyV6/AzureFileCopy.ps1

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,45 @@ $useDefaultArgumentsForBlobCopy = ($additionalArgumentsForBlobCopy -eq "")
4343

4444
# Determine AzCopy version based on Az.Accounts version
4545
$azCopyExeLocation = 'AzCopy\AzCopy.exe'
46-
$azAccountsModule = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
47-
if ($null -eq $azAccountsModule -or ([version]$azAccountsModule.Version -ge [version]'5.0.0')) {
48-
# Use latest AzCopy
49-
$azCopyExeLocation = 'AzCopy\AzCopy.exe'
50-
Write-Verbose "Using AzCopy (10.29.1) - Az.Accounts not found or >= 5.0.0"
46+
47+
# Command to run in PowerShell Core (returns version only)
48+
$coreCommand = '(Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()'
49+
# Locate pwsh.exe
50+
$pwshPath = Get-Command pwsh.exe -ErrorAction SilentlyContinue
51+
52+
if ($pwshPath) {
53+
Write-Verbose "Found PowerShell Core. Querying Az.accounts module version..."
54+
55+
# Capture output and ensure it's a clean version string
56+
$azAccountsVersionCore = & $pwshPath.Source -NoProfile -Command $coreCommand
57+
58+
# Convert to a single string, then trim
59+
$cleanVersion = ($azAccountsVersionCore -join '').Trim()
60+
61+
if ($cleanVersion -and $cleanVersion -ne "NotFound") {
62+
try {
63+
$parsedVersion = [version]$cleanVersion
64+
65+
if ($parsedVersion -ge [version]'5.0.0') {
66+
$azCopyExeLocation = 'AzCopy\AzCopy.exe'
67+
Write-Verbose "Using AzCopy (10.29.1) - Az.Accounts >= 5.0.0"
68+
} else {
69+
$azCopyExeLocation = 'AzCopy_Prev\AzCopy\AzCopy.exe'
70+
Write-Verbose "Using AzCopy_Prev (10.25.1) - Az.Accounts < 5.0.0"
71+
}
72+
} catch {
73+
Write-Error "Failed to parse Az.Accounts version: $cleanVersion"
74+
}
75+
}
76+
else {
77+
Write-Output "Az.Accounts not found in PowerShell Core"
78+
}
79+
5180
} else {
52-
# Use previous AzCopy
53-
$azCopyExeLocation = 'AzCopy_Prev\AzCopy\AzCopy.exe'
54-
Write-Verbose "Using AzCopy_Prev (10.25.1) - Az.Accounts < 5.0.0"
81+
Write-Error "PowerShell Core (pwsh.exe) is not installed or not found in PATH."
5582
}
5683
$azCopyLocation = [System.IO.Path]::GetDirectoryName($azCopyExeLocation)
5784

58-
5985
# Import RemoteDeployer
6086
Import-Module $PSScriptRoot\ps_modules\RemoteDeployer
6187

Tasks/AzureFileCopyV6/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 6,
1616
"Minor": 259,
17-
"Patch": 1
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV6/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 6,
1616
"Minor": 259,
17-
"Patch": 1
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

0 commit comments

Comments
 (0)