@@ -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
6086Import-Module $PSScriptRoot \ps_modules\RemoteDeployer
6187
0 commit comments