Total Pageviews

Wednesday, September 15, 2021

Azure cmdlets required for day today work


# Force policies to start , will take around 15minutes 

Start-AzPolicyComplianceScan -ResourceGroupName "cloud*"


#Delete az resources

Get-AzResourceGroup -Name 'Ne*' | Remove-AzResourceGroup -Force -AsJob


#Policy Related

Get-AzPolicyDefinition | Where-Object { $_.Properties.DisplayName -eq "Allowed virtual machine size SKUs" }

New-AzPolicyAssignment -Name "VMCheckingRule" -DisplayName "Checking the Rule" -Scope $rg1.Resourceid -PolicyDefinition $def


#Create new resources Group

New-AzResourceGroup -Name "MyNewRG" -Location "East US"

Get-AzResourceGroup -Name "MyNewRG"


#Check PS Version

Get-Host | Select-Object Version


#Conncet local machine to AZ portal

Install-Module -Name Az -AllowClobber -Repository PSGallery -Force

Connect-AzAccount


#new Resource group

New-AzResourceGroup -Name "NewTest" -Location "East US"


#Create Vertual Machine

New-AzVM -ResourceGroupName "NewTest" -Name "MyVM1" -Location "East US" -VirtualNetworkName "VMnet1" -SubnetName "sub1" -SecurityGroupName "NewSG" -PublicIPAddressName "myIpaddress" -OpenPorts "3389"


#Stop the VM

Stop-AzVM -ResourceGroupName "NewTest" -Name "MyVM1"


#Start the VM

Start-AzVM -ResourceGroupName "NewTest" -Name "MyVM1"


#Install Web-Server & display Hellow world

powershell.exe Install-WindowsFeature -name Web-Server -IncludeManagementTools && powershell.exe remove-item 'C:\\inetpub\\wwwroot\\iisstart.htm' && powershell.exe Add-Content -Path 'C:\\inetpub\\wwwroot\\iisstart.htm' -Value $('Hello World from ' + $env:computername


#Crete New Z: disk on VM

New-StoragePool -FriendlyName storagepool1 -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk -CanPool $true)

New-VirtualDisk -StoragePoolFriendlyName storagepool1 -FriendlyName virtualdisk1 -Size 2046GB -ResiliencySettingName Simple -ProvisioningType Fixed

Initialize-Disk -VirtualDisk (Get-VirtualDisk -FriendlyName virtualdisk1)

New-Partition -DiskNumber 4 -UseMaximumSize -DriveLetter Z


#GetVM Public ip adress

(Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $lbpipName).IpAddress


#Create a managed image of a generalized VM in Azure

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource#code-try-1


#Get azure avaialable image list

az vm image list --output table


#redeploy a VM

Set-AzureRmVm -Redeploy -ResourceGroupName NewTest -Name MyVM1 




Azure Pricing

  Azure offers pay-as-you-go and reserved instances for pricing. Azure Pricing Factors: Resource size and resource type. Different Azure loc...