Alright, mate!
so I think you’re trying to run a PowerShell script in a SQL Server Agent job, but it’s failing because the Azure PowerShell module (Az) isn’t installed or recognised in the SQL Agent’s environment.
Install the Az Module on the SQL Server Machine-> open PowerShell as an admin and run next
Install-Module -Name Az -Force -AllowClobber -Scope AllUsers
This installs the module for everyone, including SQL Agent.
next add Import-Module Az to Your Script
At the top of your script, add:
Import-Module Az
This ensures the script loads the module.
In SQL Server Agent, make sure the job step is set to run as PowerShell and not SQL Server’s built-in PowerShell.
Run the script manually in PowerShell on the SQL Server machine to make sure it works.
Ensure the SQL Server Agent account has the right permissions to access Azure resources.
If it still doesn’t work, consider using Azure Automation for running PowerShell scripts—it’s much smoother for cloud tasks.
Cheers! Alex