Create The Network Security Group and An RDP Rule
Create The Network Security Group and An RDP Rule
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized
To be able to sign in to your VM with remote desktop protocol (RDP), you'll need to have a security rule that allows RDP access on port
3389. In our example, the VHD for the new VM was created from an existing specialized VM, so you can use an account that existed on
the source virtual machine for RDP.
This example sets the network security group (NSG) name to myNsg and the RDP rule name to myRdpRule.
PowerShellCopy
$nsgName = "myNsg"
For more information about endpoints and NSG rules, see Opening ports to a VM in Azure by using PowerShell.
To enable communication with the virtual machine in the virtual network, you'll need a public IP address and a network interface.
1. Create the public IP. In this example, the public IP address name is set to myIP.
PowerShellCopy
$ipName = "myIP"
$pip = New-AzPublicIpAddress `
-Name $ipName -ResourceGroupName $destinationResourceGroup `
-Location $location `
-AllocationMethod Dynamic
2. Create the NIC. In this example, the NIC name is set to myNicName.
PowerShellCopy
$nicName = "myNicName"
$nic = New-AzNetworkInterface -Name $nicName `
-ResourceGroupName $destinationResourceGroup `
-Location $location -SubnetId $vnet.Subnets[0].Id `
-PublicIpAddressId $pip.Id `
-NetworkSecurityGroupId $nsg.Id
Set the VM name and size
This example sets the VM name to myVM and the VM size to Standard_A2.
PowerShellCopy
$vmName = "myVM"
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize "Standard_A2"
Add the NIC
PowerShellCopy
Add the OS disk to the configuration by using Set-AzVMOSDisk. This example sets the size of the disk to 128 GB and attaches the
managed disk as a Windows OS disk.
PowerShellCopy
Create the VM by using New-AzVM with the configurations that we just created.
PowerShellCopy
PowerShellCopy
You should see the newly created VM either in the Azure portal under Browse > Virtual machines, or by using the following PowerShell
commands.
PowerShellCopy