I am new to Azure and I've successfully installed PowerShell on my macOS. Now I want to run get-azvm command and stop/delete a vm from on-prem (not cloud shell).
First thing I did from Terminal: 1. PWSH to launch PowerShell 2. Connect-AzAccount, browser opens to authenticate and I get an error:
Connect-AzAccount xx: Device authentication is required. Trace ID: xx Correlation ID: xx + CategoryInfo : CloseError: (:) [Connect-AzAccount], AadAuthenticationFailedException
{ }
Please, what am I doing wrong? Do I need to register my on-prem machine somewhere?
Thanks for the help.
As mentioned in above comment - you might have conditional access policies enabled on your Azure AD so you might want to check it out and confirm. Secondly, if that's not the case - try running commands below before you access your azure resources
Add-AzAccount
Get-AzSubscription -SubscriptionId "your_azure_subscription_id" | Select-AzSubscription
$vm = Get-AzVM -ResourceGroupName "your_vm_resource_group_name" -Name "your_vm_name"
Hope it helps?
According to the error from Connect-AzAccount
, Looks your account is MFA-enabled , please use the authentication methods to authenticate. Or you can create a service principal, assign a role for it in the subscription , then you can login with the service principal and use it to Get-AzVM
, details here .
I continue with az login command. Result: You have logged in. Now let us find all the subscriptions to which you have access..
You should note, Connect-AzAccount
is used to login the Azure Powershell , az login
is used to login the Azure CLI , they are different. From the output, looks you logged in successfully in Azure CLI, you could use az account set --subscription <subscription-id>
to set the subscription which you want to get the VMs from, then use az vm list
to list VMs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.