Problems with swaping slots for azure web app

When running the commands and doing as guides i have found says i can’t get it to swap slots.


Invoke-Expression : The term ‘Swap-AzureRmWebAppSlot’ 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.
At C:\Octopus\Work\20161129171848-20\Octopus.AzureContext.ps1:86 char:2

  • Invoke-Expression ". $OctopusAzureTargetScript 

$OctopusAzureTargetScriptParamet …


    + CategoryInfo          : ObjectNotFound: (Swap-AzureRmWebAppSlot:String)  
   [Invoke-Expression], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Co 
The step failed: The remote script failed with exit code 1

I have the variable set to not use the default Octopus azurerm powershell scripts


Thanks for getting in touch.Could you please send us the following info so we can take a look:

  • A screenshot of your deployment process where we can see the Powershell script step that’s using the swap cmdlet.

  • The full script you are using on that step.

  • A full deployment log following the below instructions:

1) Add these 2 variables to your project

2) Create a new release (so the new variables take effect) and deploy it. If possible skip as many steps as you can and only leave step we are troubleshooting in order to avoid the noise in the log.

3) Send us the raw log of that deployment


here is some info

here is the script i use doing this remote on phone with rdp :slight_smile:

#Swap the staging slot into production

Get-Module -ListAvailable -Name Azure*

#Import-Module “C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Websites\AzureRM.Websites.psd1” -Verbose
Write-Host “Swapping staging and production slots…”
Swap-AzureRmWebAppSlot -ResourceGroupName TraderStage -Name TraderStage -SourceSlotName Staging -DestinationSlotName Production -Verbose

ServerTasks-15517.log.txt (101 KB)

Just to clarify, the swap-azurermwebappslot is an alias for switch-azurermwebappslot and it does not matter wich one i use.

What do you get when you run Get-command Swap-AzureRmWebAppSlot?

PS C:\Windows\system32> Get-command Swap-AzureRmWebAppSlot

CommandType Name ModuleName

Alias Swap-AzureRmWebAppSlot AzureRM.Websites

PS C:\Windows\system32>

I get the same error with switch-azurermwebappslot

Sorry I wasn’t clear on my previous message -> Did you run Get-command Swap-AzureRmWebAppSlot from Octopus using an Azure Powershell Step? Please do it if you haven’t done it already.

Also please try adding import-module AzureRM.Websites -verbose at the top of your script and let me know if that works

Hello here is the output

It uses the wrong powershell liberary.

I did do add Import-Module -Name “C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Websites\AzureRM.Websites.psd1” -Verbose

That loads the correct PS module. But still it does not work. If i run the same command on the server at the end it show’s this.

VERBOSE: Importing cmdlet ‘Start-AzureRmWebAppSlot’.
VERBOSE: Importing cmdlet ‘Stop-AzureRmWebApp’.
VERBOSE: Importing cmdlet ‘Stop-AzureRmWebAppSlot’.
VERBOSE: Importing cmdlet ‘Switch-AzureRmWebAppSlot’.
VERBOSE: Importing alias ‘Swap-AzureRmWebAppSlot’.
PS C:\Windows\system32>

It looks like octopus can’t import those 2 last cmdlet?


ServerTasks-15734.log.txt (109 KB)

ServerTasks-15736.log.txt (40 KB)

Could you please try:

  • Add a variable called Octopus.Action.PowerShell.ExecuteWithoutProfile in your project and set its value to true. This will run all your powershell scripts without any code in the profile files that might be interfering with the module import.

  • Remove any kind of module import you added in your own code in that step. Let just try to use the one that Octopus runs and see what happens.

That did not have any effect at all.

ServerTasks-15840.log.txt (151 KB)


I ran this one through one of my teammates who mentioned he had a similar case with another user. On that other thread, Pawel recommended the user to manually install the latest version of the Azure tools on the VM, and then tell Octopus not to use the Azure tools that are bundled in with Calamari (so it is forced to use the ones that were just installed).

Now, Pawel also let me know that the Azure tools bundled in Calamari were updated in Octopus 3.5.6. So you might be able to fix this only by upgrading your Octopus Server to the latest version.


A) Try to upgrade your Octopus Server to the latest version so your Calamari copy has the latest version of the Azure tools we bundled in.

B) If that doesn’t work, try what I said in the first paragraph:

manually install the latest version of the Azure tools on the VM, and then tell Octopus not to use the Azure tools that are bundled in with Calamari (so it is forced to use the ones that were just installed).

This steps would be 6 and 7 on Pawels comment:

Best regards,

Hello Dalmiro

I tried upgrading to 3.5.7 wich is the latest version i got problems that i could not deploy anything. All my settings where gone.

I have this case, and no respons on it for 9 days.

I have also tried step B in doing import module from the latest azure package.
Import-Module “C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Websites\AzureRM.Websites.psd1”

And that does not work either. And i did find Pawel’s suggestion and i tried that. That variable is in my deployment module now.

So upgrading to 3.7.3 fixed the switch-azurermwebappslot but im getting

Switch-AzureRmWebAppSlot : Run Login-AzureRmAccount to login.

But it thougt it used the setting from the account where it uses the azure account. That works fine for the staging slot creation in step 1.

ServerTasks-15984.log.txt (228 KB)

Working after adding step 7 to the variables


I’m glad to hear you got it working! would you mind explaining a bit more what is it that fixed it for you? I’m sure It’ll help any other users running into a similar situation.