Octopus deploy not recognizing Azure PowerShell cmdlets

We have some old scrips that still use Azure and AzureRm cmdlets. Since we are in the middle of migration to Octopus cloud we are not ready to update our scripts to the new Az module yet, I created a new static worker with Azure and AzureRm modules installed to use. We have old Azure scripts in the second and fourth step of our deployment. All three step works fine except the deployment keeps failing at the same point in the fourth step with the following
July 19th 2022 12:29:46Error
ObjectNotFound: The term ‘Get-AzureEnvironment’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
July 19th 2022 12:29:46Error
At C:\Octopus\Work\20220719172919-7579-2\Octopus.AzureContext.ps1:222 char:33
July 19th 2022 12:29:46Error

  •         $AzureEnvironment = Get-AzureEnvironment | Where-Object { ...

I found that we don’t have that statement in our script and it is failing at Octopus.AzureContext.ps1:222 .

Any idea why Octopus is not recognizing the cmdlet at that point but not in other places of our script?

Note: I had followed most of the suggested options from support tickets similar to mine. I have restarted the tentacle service in the worker. I have installed Azure CLI in the worker. I tried installing Az module and Enable-AzureRmAlias -Scope LocalMachine in another worker but that too throwing Azure errors caused by Import Azure module like statements in our script which might need to be changed that we not ready. So I’m focusing on the worker with the old Azure modules.

Hi @subadhra.raja,

Thank you for reaching out! I’m sorry to hear you’re having trouble using the legacy Azure cmdlets, but I’m happy to help take a look.

As a first step in troubleshooting this, could you let me know what version of Octopus you are currently using?

I also did some testing on my side and I’m curious to see how this lines up with your environment -

First, I installed the legacy Azure cmdlets via the following command on Microsoft’s website:

Install-Module -Name Azure -AllowClobber

Note the use of -AllowClobber in this command, as Microsoft mentions that the Azure Service Management module shares dependencies with the Azure PowerShell Resource Manager modules.

I then checked my version of the Azure cmdlets via this command:

Get-InstalledModule -Name Azure -AllVersions |
  Select-Object -Property Name,Version

Which returned the following:

Name  Version
----  -------
Azure 5.3.1

I was then able to confirm I had the Get-AzureEnvironment cmdlet installed via the following command:

Get-Command -Type Cmdlet | Where-Object {$_.Name -like '*Get-AzureEnvironment*'} | Sort-Object -Property Noun | Format-Table -GroupBy Noun

Which returned the following:

CommandType     Name                        Version    Source
-----------     ----                                              
Cmdlet          Get-AzureEnvironment        5.3.1      Azure

Can you let me know what version you get for the Azure cmdlets on this worker when manually running the command I mentioned above? And also if you are able to pull just the Get-AzureEnvironment cmdlet as I did?

If this doesn’t help shed any light on this issue would you also be able to upload the full task log for this so I can review it? Here is a secure link to upload for this if you don’t want to share it publicly on the forum.

Best regards,


Hi @britton.riggs,

Thanks for the quick response.
I am using Octopus cloud v2022.3. I am not sure if I had used -AllowClobber during the module installation.
I am getting the same results for those two commands as you

I will share you the task log in few minutes. Thanks

Hi @subadhra.raja,

Thank you for the update, and also for uploading the log file!

Everything looks fine to me so far, but in looking through some old support tickets I saw another user was able to resolve this by installing the Azure Az PowerShell module using the following command:

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Can you try this and see if it resolves your error as well?

Looking forward to hearing back from you!



Hi @britton.riggs,

Sorry, I couldn’t get back to reply earlier.
So, I got this issue resolved by completely removing the AzureRm module using
foreach ($AZModule in (Get-Module -Name AzureRM* -ListAvailable).Name | Get-Unique)
Uninstall-Module $AZModule -Verbose

and then installed the Azure Az module using the command you provided above
" Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force " then used the Alias command as below
Enable-AzureRmAlias -Scope LocalMachine

Now I am able to deploy using the old Azure script with a warning like this

Thanks for the help!

1 Like

Hi @subadhra.raja,

Thank you for the update, and I’m happy to hear you were able to get unblocked!

Happy Deployments!


This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.