Lab 08 - Manage Virtual Machines (Task5~Task6)_Cloudshell(用powershell跟bash方式)
Task 5: Create a virtual machine using Azure PowerShell
Use the icon (top right) to launch a Cloud Shell session. Alternately, navigate directly to https://shell.azure.com.
Be sure to select PowerShell. If necessary, configure the shell storage.
Run the following command to create a virtual machine. When prompted, provide a username and password for the VM. While you wait check out the New-AzVM command reference for all the parameters associated with creating a virtual machine.
New-AzVm `
-ResourceGroupName 'AZ-104-M8-A728GIWJRI' `
-Name 'myPSVM' `
-Location 'East US' `
-Image 'Win2019Datacenter' `
-Zone '1' `
-Size 'Standard_D2s_v3' `
-Credential (Get-Credential)
Once the command completes, use Get-AzVM to list the virtual machines in your resource group.
Get-AzVM `
-ResourceGroupName 'AZ-104-M8-A728GIWJRI' `
-Status
Use Stop-AzVM to deallocate your virtual machine. Type Yes to confirm.
Stop-AzVM `
-ResourceGroupName 'AZ-104-M8-A728GIWJRI' `
-Name 'myPSVM'
When you use Azure to stop your virtual machine, the status is deallocated. This means that any non-static public IPs are released, and you stop paying for the VM’s compute costs.
Task 6: Create a virtual machine using the CLI
Use the icon (top right) to launch a Cloud Shell session. Alternately, navigate directly to https://shell.azure.com.
Be sure to select Bash. If necessary, configure the shell storage.
Run the following command to create a virtual machine. When prompted, provide a username and password for the VM. While you wait check out the az vm create command reference for all the parameters associated with creating a virtual machine.
az vm create --name myCLIVM --resource-group AZ-104-M8-A728GIWJRI --image Ubuntu2204 --admin-username localadmin --generate-ssh-keys
Once the command completes, use az vm show to verify your machine was created.
Verify the powerState is VM Running.
az vm show --name myCLIVM --resource-group AZ-104-M8-A728GIWJRI --show-details
Use az vm deallocate to deallocate your virtual machine. Type Yes to confirm.
az vm deallocate --resource-group AZ-104-M8-A728GIWJRI --name myCLIVM
Use az vm show to ensure the powerState is VM deallocated.
留言
張貼留言