I am attempting to use azure keyvault in a powershell script that is used by a github action. HEre is an example of my code, which worked at least once earlier today
$TenantID = my_tenant_id"
$securePassword = "passowrd_for_key_vault_account" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "my_application_id", $securePassword
Connect-AzAccount -ServicePrincipal -Credential $Credential -TenantID $TenantID
When I attempt to run this, I get the following error
The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.
When I run Import-Module Az.Accounts I get
Import-Module: Assembly with same name is already loaded
I am installing & Importing the module earlier in my code with the following
Install-Module -Name Az -scope currentuser -force -AllowClobber
Import-Module Az
I tried to connect an azure service account I was expecting it to log in and continue on to pull information from key vault
AZ module seems to keep breaking in powershell with a message about import-module:
This is usually the case if you have an AzureRM module installed in addition to the Az modules in PowerShell library. Even with the Az/Az.Accounts module installed, there may be issues with PowerShell if AzureRM was previously installed.
As a result, use this command to uninstall the AzureRM module.
uninstall-AzureRM
After executing it, I tried connecting Az account and it worked successfully.
$TenantID = "tenant_ID"
$securePassword = "secret/password" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "AppID", $securePassword
Connect-AzAccount -ServicePrincipal -Credential $Credential -TenantID $TenantID
Output:

Note:
update-module
get-module Az.accounts

get-module -ListAvailable

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With