Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Part 1 - Set up credentials
$VMLocalAdminUser = "LocalAdminUser"
$VMLocalAdminSecurePassword = ConvertTo-SecureString "NotARealPassword!@#$%433" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword);
#Part 2 - create RG and VM
New-AzResourceGroup -Name todeleteRG -Location EastUS
New-AzVm `
-ResourceGroupName "todeleteRG" `
-Name "todeleteVM" `
-Location "East US" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress" `
-Credential $Credential `
-OpenPorts 80, 443
#Part 3 - Install IIS and add default page with computer name
Set-AzVMExtension -ResourceGroupName "todeleteRG"`
-ExtensionName "IIS" `
-VMName "todeleteVM" `
-Location "East US" `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.8 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}'
#part 4 - Clean things up
remove-azresourcegroup -name "todeleteRG" -force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment