Trying to use an Azure Automation Account to shutdown/startup a vm based on a set schedule. I’ve assigned the account role as a Contributor but can’t seem to get past for it to log in correctly getting this error:
You may need to login again after updating "EnableLoginByWam".
Key : EnableLoginByWam
Value : False
Scope : CurrentUser
AppliesTo : Az
HelpMessage : When enabled, Web Account Manager (WAM) will be the default interactive login experience. It will fall
back to using the browser if the platform does not support WAM. For more details please refer to
https://go.microsoft.com/fwlink/?linkid=2272007
DefaultValue : True
You may need to login again after updating "EnableLoginByWam".
Here is the script I’m using:
# Log into Azure
Update-AzConfig -EnableLoginByWam $false
Connect-AzAccount -UseDeviceAuthentication
# Get the virtual machine
$resourceGroupName = "MY-RG"
$vmName = "MY-AZURESERVER"
$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
# Stop the VM
if ($vm.PowerState -eq "Running") {
Write-Host "Stopping VM..."
Stop-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
Write-Host "VM stopped successfully"
}
else {
Write-Host "VM is already stopped"
}
# Start the VM
if ($vm.PowerState -eq "Stopped") {
Write-Host "Starting VM..."
Start-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
Write-Host "VM started successfully"
}
else {
Write-Host "VM is already running"
}