PowerShell Flashcards
Connect to Azure
Connect-AzAccount
Create Virtual Machine
New-AzVm
- ResourceGroupName - Name - Credential - Location - Image <img>
Example:
New-AzVM -ResourceGroupName az104-prereq-rg -Name vm1 -Credential (Get-Credential) -Image MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition-core:latest -Size Standard_DC1s_v2
Delete a VM
Remove-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
Stop/Start a VM
Stop-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
Start-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
Get the SKUs of available and unavailable compute resources
Get-AzComputeResourceSku -Location
Get-AzComputeResourceSku “southeastasia”
Allow SSH into VM
Add these params to New-AzVM command.
- OpenPorts 22
- PublicIpAddressName “testvm-01”
*Note port 22 allows for SSH
ssh @
e.g. ssh bob@205.22.16.5
variable declaration
$loc = "East Us" $iterations = 3
Variables and objects
Variables can hold objects
$adminCredential = Get-Credential
Using variables
$loc = “East US”
New-AzResourceGroup -Name “MyResourceGroup” - Location $loc
Loops
For ($i = 1; $i -lt 3; $i++)
{
$i
}
Script Params
.\setupEnvironment.ps1 -size 5 -location “East US”
param([string]$location, [int]$size)
What VM Images are available in region?
What publishers are available?
Get-AzVMImagePublisher
-Location
What offers are available?
Get-AzVMImageOffer
-Location
-PublisherName
What VMImages are available? Get-AzVMImageSku -Location -PublisherName -Offer