dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 787 forks source link

Azure Automation Account - issue loading the module #9363

Closed Xeno468 closed 1 month ago

Xeno468 commented 1 month ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Connect-DbaInstance: Line | 9 | $Server = Connect-DbaInstance -SqlInstance $ConnString -DisableEx … | ~~~~~~~~~~~~~~~~~~~ | The 'Connect-DbaInstance' command was found in the module 'dbatools', but the module could not be loaded. For more information, run 'Import-Module dbatools'.

Steps to Reproduce

I attempted to reduce possible points of failure by creating this simple piece of code, but I still encountered the error.

Here's the code:

$ConnString = "Data Source=TCP:[AZURE Database],1433;Database=[dbname];User ID=[Username];Password=[Password];Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;" 
$Server = Connect-DbaInstance -SqlInstance $ConnString  -ConnectTimeout 30
Write-Output  $Server

Additionally, I tried to manually import the module using this command: Import-Module dbatools. However, I received the following error:

Import-Module dbatools | ~~~~~~~~~~~~~~~~~~~~~~ | Couldn't import dbatools library | Could not load file or assembly 'System.Management.Automation, Version=7.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

thanks

Please confirm that you are running the most recent version of dbatools

Azure Automation Powershell 7.2 dbatools version 2.1.16 dbatools library 2024.4.12

Other details or mentions

No response

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name Value


PSVersion 7.2.0 PSEdition Core GitCommitId 7.2.0 OS Microsoft Windows 10.0.17763 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

SQL Server Edition and Build number

NA

.NET Framework Version

PSChildName Version


Client 4.7.03190

Full 4.7.03190

Client 4.0.0.0

niphlod commented 1 month ago

hi @Xeno468 , I have various degrees of failures on azure automation myself. Can you try running a 5.1 host and see if it has the same kind of errors ? In 7.2, even the "official" module from MS doesn't work https://github.com/microsoft/SQLServerPSModule/issues/72

potatoqualitee commented 1 month ago

Can you pls tell me how to to test this? I got it to import but dont know how to do anything else. I only use azure automation to see if dbatools can load from the Modules panel.

image

niphlod commented 1 month ago

import goes through always, if you try to run a "simple" connect-dbainstance it may reveal breaking, as using invoke-sqlcmd does for SQLServerPS .

Runbooks --> Create a runbook --> runbook type = powershell, version you may choose (7.2. if modules are imported for 7.2). Then you paste the code and you can either test it or run it after saving it

potatoqualitee commented 1 month ago

Thank you! Gonna try now.

Xeno468 commented 1 month ago

hi @Xeno468 , I have various degrees of failures on azure automation myself. Can you try running a 5.1 host and see if it has the same kind of errors ? In 7.2, even the "official" module from MS doesn't work microsoft/SQLServerPSModule#72

The module is working in powershell 5.1. Other modules we use in our case ( if we want to stay up to date) work only in powershell 7.2. So that's why I need to change for powershell 7.2.

wsmelton commented 1 month ago

Azure Automation is such a sad implementation of PowerShell 7 support...7.2 which by November will be out of support 🐼 ....Azure team answer me WHY???!!! 😿 😭

image image

Anyway, this specific message means the module is incompatible with 7.2 of PowerShell. The library imports fine, it is the module itself that will not import.

image

That error indicates something we are trying to do isn't compatibile in the build of PowerShell 7.2 Azure Automation is using.

This output shows you we require the lastest version of that assembly in PowerShell 7.2 to work but Azure Automation team is using a lower build.

image

How old/lower of a build you ask? They are on the RTM release of 7.2.0 😱 (shocker, not really).

image

The latest release of PS 7.2 is 7.2.19. They are on a release from....wait for it..7.2.0 - 2021-11-08!!!

Sorry but this is on Azure to fix. You can try submitting a support ticket and telling them they are running a version of PowerShell that the PowerShell Team is not supporting.