Hello,
I’m trying to do something with Azure that unfortunately needs to be done through the new-ish Az
PowerShell, as opposed to AzureRm
PowerShell. Sadly though, I can’t seem to get it to work on our self-hosted Octopus server
After finding this support topic, I’ve installed the Az
module on the Octopus server as an administrator, and I can import and use the module when running PowerShell directly on the server.
Install-Module -Name Az -AllowClobber
Import-Module Az
### Test the 'Az' PowerShell module
$storageAccount = Get-AzStorageAccount -ResourceGroupName "my-resource-group" -AccountName "mystorageaccount"
However, when I try to use the Az
module in a Octopus step (Run a Script), I get an error -
Import-Module : The specified module ‘Az’ was not loaded because no valid module file was found in any module directory.
How can I use the Az
PowerShell module in Octopus, without breaking AzureRm
?
Failing Step
$accountClientId = $OctopusParameters["Az.Account.Client"]
$accountClientPassword = $OctopusParameters["Az.Account.Password"]
$accountTenantId = $OctopusParameters["Az.Account.TenantId"]
$accountSubscriptionId = $OctopusParameters["Az.Account.SubscriptionNumber"]
$resourceGroupName = $OctopusParameters["Az.StorageAccount.ResourceGroup"]
$storageAccount = $OctopusParameters["Az.StorageAccount.Name"]
$indexDocument = $OctopusParameters["Az.StorageAccount.StaticWebsite.IndexDocument"]
$404Document = $OctopusParameters["Az.StorageAccount.StaticWebsite.404Document"]
### Import 'Az' PowerShell.
Import-Module Az
### Connect to the relevant Azure account and set the subscription to use.
$securePassword = ConvertTo-SecureString $accountClientPassword -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential($accountClientId, $securePassword)
Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $accountTenantId
Set-AzContext -Subscription $accountSubscriptionId
### Get the Storage Account context.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccount
$context = $storageAccount.Context
### Enable the static website and set the index and error documents.
Enable-AzStorageStaticWebsite -Context $context -IndexDocument $indexDocument -ErrorDocument404Path $404Document
Thanks,
David