Simple PowerShell Script to Start or Stop an Azure Virtual Machine using Azure Automation with a Managed Identity. Uses the new ("Az") Azure PowerShell module.
Hi. When I try to use your runbook script - runbook test returned me following:
Script started at 2023-09-21 10:31:11
Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
I can't delete AzureRM modules from Automation Accounts Modules - "Delete" button not active.
What can I do? Help, plz!!!!
Get-AzVM : Resource group 'XXXXXXXX' could not be found. ErrorCode: ResourceGroupNotFound ErrorMessage: Resource group 'XXXXXXXX' could not be found. ErrorTarget: StatusCode: 404 ReasonPhrase: Not Found OperationID : 91c0a45d-66f9-49f7-a464-ce7113a2bc61 At line:133 char:16 + ... $VMs = Get-AzVM -ResourceGroupName $ResourceGroupName -VMName $V ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzVM], ComputeCloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.GetAzureVMCommand
The status of the Job gives Completed
By the way, Thanks for the script. I am very happy with it. Much better than the old graphic powershell scripts: StartAzureV2VMs/StopAzureV2VMs