To start, restart, stop, or delete multiple Azure virtual machines (VMs), you can use Azure PowerShell or the Azure CLI. Here are the steps using both methods:
Using Azure PowerShell:
Install Azure PowerShell: If you haven't already, install the Azure PowerShell module on your local machine. You can follow the instructions provided by Microsoft to install Azure PowerShell: https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-12.0.0
Connect to your Azure account: Open PowerShell and run the following command to sign in to your Azure account:
powershellConnect-AzAccount
Select the Azure subscription: If you have multiple Azure subscriptions, use the following command to select the appropriate subscription:
powershellSet-AzContext -SubscriptionId <SubscriptionId>
Start, restart, stop, or delete VMs: Use the appropriate commands to manage your VMs. For example:
- To start VMs:powershell
Start-AzVM -ResourceGroupName <ResourceGroupName> -Name <VM1Name>, <VM2Name>, ...
- To restart VMs:powershell
Restart-AzVM -ResourceGroupName <ResourceGroupName> -Name <VM1Name>, <VM2Name>, ...
- To stop (deallocate) VMs:powershell
Stop-AzVM -ResourceGroupName <ResourceGroupName> -Name <VM1Name>, <VM2Name>, ...
- To delete VMs:powershell
Remove-AzVM -ResourceGroupName <ResourceGroupName> -Name <VM1Name>, <VM2Name>, ...
- To start VMs:
Using Azure CLI:
Install Azure CLI: If you haven't already, install the Azure CLI on your local machine. Follow the instructions provided by Microsoft to install Azure CLI: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
Sign in to your Azure account: Open the command prompt or terminal and run the following command to sign in to your Azure account:
bashaz login
Select the Azure subscription: If you have multiple Azure subscriptions, use the following command to select the appropriate subscription:
bashaz account set --subscription <SubscriptionId>
Start, restart, stop, or delete VMs: Use the appropriate commands to manage your VMs. For example:
- To start VMs:bash
az vm start --resource-group <ResourceGroupName> --name <VM1Name> <VM2Name> ...
- To restart VMs:bash
az vm restart --resource-group <ResourceGroupName> --name <VM1Name> <VM2Name> ...
- To stop (deallocate) VMs:bash
az vm stop --resource-group <ResourceGroupName> --name <VM1Name> <VM2Name> ...
- To delete VMs:bash
az vm delete --resource-group <ResourceGroupName> --name <VM1Name> <VM2Name> ...
- To start VMs:
Remember to replace <ResourceGroupName>
, <VM1Name>
, <VM2Name>
, and <SubscriptionId>
with the actual names and IDs relevant to your Azure environment.
Both Azure PowerShell and Azure CLI provide powerful automation capabilities, so you can script or loop through a list of VMs to perform bulk operations efficiently.
No comments:
Post a Comment