dbatools
dbatools copied to clipboard
Connect-DbaInstance breaks Get-AzStorageBlob
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Very very weird interaction here.
If I call Connect-DbaInstance before using Get-AzStorageBlob, Get-AzStorageBlob will crash;
https://github.com/Azure/azure-powershell/issues/24748
Steps to Reproduce
$sqlInstance = Connect-DbaInstance -SqlInstance "localhost";
$path="https://xxx.blob.core.windows.net/exchange/testbackups/"
$ctx = New-AzStorageContext -StorageAccountName $backupUrl.storageAccountName -SasToken $backupUrl.sasToken;
$blobs = Get-AzStorageBlob -Container $backupUrl.container -Context $ctx -Prefix $backupUrl.prefix;
this does work
$path="https://xxx.blob.core.windows.net/exchange/testbackups/"
$ctx = New-AzStorageContext -StorageAccountName $backupUrl.storageAccountName -SasToken $backupUrl.sasToken;
$blobs = Get-AzStorageBlob -Container $backupUrl.container -Context $ctx -Prefix $backupUrl.prefix;
Please confirm that you are running the most recent version of dbatools
?
Other details or mentions
No response
What PowerShell host was used when producing this error
Windows PowerShell (powershell.exe)
PowerShell Host Version
Name Value
PSVersion 5.1.20348.2227 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.20348.2227 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
SQL Server Edition and Build number
Microsoft SQL Server 2022 (RTM-GDR) (KB5035432) - 16.0.1115.1 (X64) Mar 15 2024 01:13:46 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro N 10.0 <X64> (Build 22631: ) (Hypervisor)
.NET Framework Version
PSChildName Version
Client 4.8.04161 Full 4.8.04161 Client 4.0.0.0
Seems like this could be conflicting versions of Azure Identity. Can you load dbatools after and see if it still works? If it continues not to work, I don't know how to fix it, unfortunately. Maybe try in Core as it loads DLLs differently (I think)
This is by nature of the library version we use for Azure authentication being lower to the one used by Azure PowerShell modules...or version mismatch around APIs hit (could be both or one of the two).
It will likely exists for the other modules that deal with identity auth and not just storage commands.
Maybe you can expand on why you need to use those Az commands with dbatools in the same session?
Also what does "crash" mean?
I can reproduce the issue and the get the error message that is shown in the linked issue. Only importing dbatools is needed, no connection to an instance is needed.
Workaround: Import Az modules first, then dbatools:
Import-Module Az.Accounts, Az.Storage
Import-Module dbatools
Just another example why I always import all modules at the top of the script in the "correct" order...
Will close this now, but can reopen if needed.