Skip to content

Instantly share code, notes, and snippets.

@waiholiu
Created October 3, 2021 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waiholiu/34cb9648f643c8aefa242e4e46db3c04 to your computer and use it in GitHub Desktop.
Save waiholiu/34cb9648f643c8aefa242e4e46db3c04 to your computer and use it in GitHub Desktop.
#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