Script to us in Azure to create Windows 11 test devices:
#Create Windows 11 test device
$ProjectName = "Project" #Name of what I'm working on so that I know which RG is which
$ComputerNumber = "01" #In case I need more than one computer for the same project I can increment this
$RGPrefix = "RG-Temp-" #Prefix for the resource group. I use this to automate deletion of all of my temp resources nightly in order to avoid running up costs in Azure
$vmName = $ProjectName + $ComputerNumber
$myResourceGroup = $RGPrefix + $ProjectName #Concatonates the Prefix with the Project name to create the resource group name
$vnetName = $myResourceGroup + "-vNet" #Name for the virtual network
$subnetName = $myResourceGroup + "-subnet" #name for the subnet
$publicIpName = $myResourceGroup + "-PubIP" #name for the public IP
$nsgName = $myResourceGroup + "-netsecGroup" #name for the network security group
$nicName = $vmName + "-NIC"
$adminUser = $vmName + "Admin"
$adminPassword = $adminUser + "PW"
az group create --name $myResourceGroup --location 'Canada Central' #create the resource group for the new test machine
az network vnet create --name $vnetName --resource-group $myResourceGroup --subnet-name $subnetName #create the public IP address for the machine
az network public-ip create --name $publicIpName --resource-group $myResourceGroup
az network nsg create --name $nsgName --resource-group $myResourceGroup #create the network security group
az network nic create --name $nicName --resource-group $myResourceGroup --vnet-name $vnetName --subnet $subnetName --public-ip-address $publicIpName --network-security-group $nsgName #create a virtual nic
az vm create --resource-group $myResourceGroup --name $vmName --image MicrosoftWindowsDesktop:Windows-11:win11-22h2-pro:latest --admin-username $adminUser --admin-password $adminPassword --nics $nicName --nsg-rule RDP #Create the VM
az network nsg rule create --resource-group $myResourceGroup --nsg-name $NsgName --name Allow-RDP --protocol Tcp --direction Inbound --priority 1000 --source-address-prefixes '*' --source-port-ranges '*' --destination-address-prefixes '*' --destination-port-ranges 3389 --access Allow #ensure RDP is allowed on the network security group
No comments:
Post a Comment