Pleasant day all,
My Azure free trial has expired and I am trying to create a full shell script for creating a new VM with all settings. I am requesting help in correcting my script.
It appears to do everything with AZ Shell, you need to create the Virtual Network and Subnets first. Is this correct?
Is there a way to assign RAM size in the VM Creation script?
Create Windows 2016 VM
az vm create
--resource-group test-rg-1
--name test-win2016-ap
--admin-password Password1
--admin-username Admin1
--os-disk-name Win2k16Test
--os-disk-size-gb 72
--image WindowsServer 2016
--size Standard_DS2_v2
-Location "East US" `
-VirtualNetworkName "vnet-01" `
-SubnetName "vnet-subnet-01" `
-SecurityGroupName "test-win16-nsg" `
-OpenPorts 80,3389,443
Create LinuxVM
# Create a virtual network card and associate with public IP address and NSG
$nic = New-AzNetworkInterface `
-Name "testRedhatNic1" `
-ResourceGroupName "test-rg1" `
-Location "EastUS" ` -SubnetId $vnet.Subnets[0].Id `
-PublicIpAddressId $pip.Id `
-NetworkSecurityGroupId $nsg.Id
# Define a credential object
$securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("Admin1", $securePassword)
# Create a virtual machine configuration
$vmConfig = New-AzVMConfig `
-VMName testRedhat
-VMSize "Standard_D1"
--os-disk-name RedHat7.4Test
--os-disk-size-gb 32
Set-AzVMOperatingSystem
-Linux
-ComputerName "TestRedhat1"
-Credential $cred
-DisablePasswordAuthentication
Set-AzVMSourceImage
-PublisherName "Canonical"
-Offer "RedHat"
-Skus "7.4-LVM"
-Version "latest"
Add-AzVMNetworkInterface
-Id $nic.Id
-Location "East US" `
-VirtualNetworkName "vnet-01"
-SubnetName "vnet-subnet-02"
-SecurityGroupName "test-RedHat-nsg"
-OpenPorts 80,3389,443
# Configure the SSH key
$sshPublicKey = cat ~/.ssh/id_rsa.pub Add-AzVMSshPublicKey
-VM $vmconfig `
-KeyData $sshPublicKey `
-Path "/home/azureuser/.ssh/authorized_keys"