0% found this document useful (0 votes)
79 views

Create The Network Security Group and An RDP Rule

This document provides steps to create a virtual machine (VM) in Azure from a specialized VM disk image, including: 1. Creating a network security group (NSG) and rule to allow RDP access on port 3389 2. Creating a public IP address and network interface card (NIC) for external connectivity 3. Configuring the VM name, size, NIC, OS disk, and creating the VM 4. Verifying the new VM was successfully created

Uploaded by

mateigeorgescu80
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Create The Network Security Group and An RDP Rule

This document provides steps to create a virtual machine (VM) in Azure from a specialized VM disk image, including: 1. Creating a network security group (NSG) and rule to allow RDP access on port 3389 2. Creating a public IP address and network interface card (NIC) for external connectivity 3. Configuring the VM name, size, NIC, OS disk, and creating the VM 4. Verifying the new VM was successfully created

Uploaded by

mateigeorgescu80
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Part 4

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized

Create the network security group and an RDP rule

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"

$rdpRule = New-AzNetworkSecurityRuleConfig -Name myRdpRule -Description "Allow


RDP" `
-Access Allow -Protocol Tcp -Direction Inbound -Priority 110 `
-SourceAddressPrefix Internet -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 3389
$nsg = New-AzNetworkSecurityGroup `
-ResourceGroupName $destinationResourceGroup `
-Location $location `
-Name $nsgName -SecurityRules $rdpRule

For more information about endpoints and NSG rules, see Opening ports to a VM in Azure by using PowerShell.

Create a public IP address and NIC

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

$vm = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id


Add the OS disk

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

$vm = Set-AzVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType


Standard_LRS `
-DiskSizeInGB 128 -CreateOption Attach -Windows
Complete the VM

Create the VM by using New-AzVM with the configurations that we just created.

PowerShellCopy

New-AzVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm

If this command is successful, you'll see output like this:

PowerShellCopy

RequestId IsSuccessStatusCode StatusCode ReasonPhrase


--------- ------------------- ---------- ------------
True OK OK

Verify that the VM was created

You should see the newly created VM either in the Azure portal under Browse > Virtual machines, or by using the following PowerShell
commands.

PowerShellCopy

$vmList = Get-AzVM -ResourceGroupName $destinationResourceGroup


$vmList.Name

You might also like