Access Azure Windows VM Through Powershell

Access Azure Windows VM Through Powershell

Access Azure Windows VM through Powershell

In this blog, we will show you the steps to access azure windows VM through PowerShell on Windows 2016.

REQUIREMENTS

  • Microsoft Azure Subscription
  • Virtual Machine

ADDING FIREWALL RULES FOR POWERSHELL REMOTING

  • Log in to the Windows Azure portal using your subscription credentials.
image
  • Click on the existing network security group. In this demo, it’s az-networksecuritygroup from the dashboard.
image
  • In another way, you can also find the network security group from the Azure service list.
image
image
  • Click on the Inbound security rules option.
image
  • Click on Add button.
image
  • Now click on Basic.
image
  • WINRM will run on either ports 5985 and 5986. The port 5985 is for HTTP and 5986 is for HTTPS. To add the HTTPS WIRM Select the service type as WinRM which will select the port 5986 automatically. Make sure that you have set the priority and name for this rule. Click on OK.
image
  • Repeat the same above steps and add the port 5985 in the NSG group.
image
  • The new rule will be displayed in the Inbound rules list.
image

FINDING AZURE VM PUBLIC ADDRESS

  • From the Azure portal, Click on the Virtual Machines service link.
image
  • Click on the VM to access through PowerShell remoting and select the public IP address.
image
image

CONFIGURE WINRM ON AZURE VM

  • Log in to the windows azure VM and execute the below command from the command prompt and execute the below command.

winrm quickconfig

image
  • It prompted us to configure the WinRM for remote management. Type Y and press Enter.
image
  • Run the winrm quickconfig command to verify the settings.
image

ADDING AZURE VM IP INTO TRUSTED HOSTS

  • Open the PowerShell window from a VM.

Note: In this demo, we are using windows 2016 VM

  • Execute the below command to add the Azure VM into the trusted host.

Syntax: Set-Item WSMan:\localhost\Client\TrustedHosts –Value <IP address>

Example: Set-Item WSMan:\localhost\Client\TrustedHosts -Value 52.172.27.157

image
  • It prompts us for the confirmation. Accept the change by entering Y.
image

ACCESSING VM THROUGH POWERSHELL REMOTING

  • From the PowerShell window, execute the below command to start a PowerShell session on remote VM.

Syntax: Enter-PSSession –ComputerName <IP Address> -Credential Get-Credential

Example: Enter-PSSession -ComputerName 52.172.27.157 -Credential Get-Credential

image
  • Provide the Azure VM login credentials and click OK.
image
  • Once the credentials are authenticated successfully, you will get the PowerShell prompt as shown below.
image
  • Type the command hostname to find verify the Azure VM name.
image
VIDEO

Thanks for reading this blog. We hope it was useful for you to learn about accessing azure VM through PowerShell commands.

Loges

Leave a Reply

Your email address will not be published. Required fields are marked *