Skip to content

Instantly share code, notes, and snippets.

@doctordns
Last active February 22, 2022 06:12
Show Gist options
  • Save doctordns/c050c1eaf1c1acfdd0978e5cc24bb5e6 to your computer and use it in GitHub Desktop.
Save doctordns/c050c1eaf1c1acfdd0978e5cc24bb5e6 to your computer and use it in GitHub Desktop.
# This Gist is the code for the VM quick create article at:
# https://docs.microsoft.com/azure/virtual-machines/windows/quick-create-portal
# DoctorDNS@Gmail.Com
# Connect to Azure
Connect-AzAccount
# Create a new resource group
New-AzResourceGroup -Name MyResourceGroup -Location 'UKSouth'
# Create Credential for user
$User = 'User42'
$Password = 'VeryL0ngSt!ng'
$PWSS = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Cred = [System.Management.Automation.PSCredential]::New(
$User, $PWSS)
# Create VM
$VMHT = @{
ResourceGroupName = 'MyResourceGroup'
Name = 'MyVM'
Location = 'East US'
VirtualNetworkName = 'MyVnet'
SubnetName = 'MySubnet'
SecurityGroupName = 'MyNetworkSecurityGroup'
PublicIpAddressName = 'MyPublicIpAddress'
OpenPorts = @(80,3389)
Credential = $Cred
}
New-AzVm @VMHT
# Get public IP address
Get-AzPublicIpAddress -ResourceGroupName "MyResourceGroup" |
Select-Object -Property 'IpAddress'
# Open RDP session to VM
$IP = Get-AzPublicIpAddress -ResourceGroupName "MyResourceGroup" |
Select-Object -ExpandProperty 'IpAddress'
mstsc /v:$IP
# Inside the VM, open a PowerShell window and install IIS
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# View the Website in action:
Start-Process "http://$IP"
# Clean up resources
Remove-AzResourceGroup -Name MyResourceGroup
# view IIS in VM
Start-Process "http://$IP"
Get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment