Created
October 3, 2021 03:22
-
-
Save waiholiu/34cb9648f643c8aefa242e4e46db3c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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