I am trying to run a runbook to start a VM using a managed identity. With a runas account it works but because Microsoft says it recommended to use a managed identity, I want to try it.
This is part of the script that I got from internet and that works with runas account:
$ResourceGroupName = 'test'
$AzureVMName = 'test'
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Login-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
And this is the script that I tried to use now but does not work:
Connect-AzAccount -Identity
$ResourceGroupName = 'test'
$AzureVMName = 'test'
"Starting Azure VM..."
Start-AzureRmVM -Name $AzureVMName -ResourceGroupName $ResourceGroupName
I always get following error:
Environments
{[AzureChinaCloud, AzureChinaCloud], [AzureCloud, AzureCloud], [AzureGermanCloud, AzureGermanCloud], [AzureUSGovernme... Starting Azure VM... Run Login-AzureRmAccount to login.
I have tried many things but I cannot get it working...