Enabling Remote Powershell connection to Azure Virtual Machine

Posted: November 16, 2016 in Azure

Setting public DNS name of Azure VM

After Azure VM is installed public DNS name is empty by default.

On Azure dashboard click on Virtual Machine and then click on selected area (picture below)

1-1.PNG

Set desired name:

1-2

Enable WinRM 

We need to modify Network Security Group (NSG)

Click All Resources

1-1

Select NSG

1-1

Click On Inbound security rules

1-1.PNG

Click Add

1-1

Enter Rulename,from service drop-down choose WinRm,click Allow and OK

1-1

1-1

Now enable port 5986 on Azure VM (Run Powershell As admin):

New-NetFirewallRule -Displayname "Allow PS Remoting" -direction inbound -LocalPort 5986 -Protocol tcp -Action allow

Create self-signed certificate (Run Powershell As admin):

New-SelfSignedCertificate -DnsName server-2016.westeurope.cloudapp.azure.com -CertStoreLocation Cert:\LocalMachine\My

Copy Thumbprint to clipoard

1-3

Configure WinRM to listen on port 5986 (run CMD as admin),we can’t run this command from Powershell (Error: Invalid use of command line. Type “winrm -?” for help.)

winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="server-2016.westeurope.cloudapp.azure.com";CertificateThumbprint="4C73BF0432E120DDDEABE4B9D19AA0B9C280A18B"}

Export Self-signed certificate from Azure VM

Start-run-mmc Add/Remove SnapIn

1-5a.png

Click Certificate

1-5b.png

Computer Account

1-5c

Local Computer

1-5d

Click Personal-Certificates-Self-signed certificate-Right click-All-Tasks-Export

1-5e

Don’t export Private Key

1-5f

Click Next

1-5g

Export certificate to file

1-5h
Importing certificate on client machine
After copying certificate to client machine,on the client,right click on certificate-Install Certificate

1-6.png

Current User

1-7

Place all certificates in the following store

1-8

Trusted Root Certification Authorities

1-9

 

 

1-5

 

 

Connect to Azure VM:

Enter-PSSession -ComputerName server-2016.westeurope.cloudapp.azure.com -Credential spiderman -UseSSL

1-10

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s