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
- Microsoft Azure Subscription
- Virtual Machine
ADDING FIREWALL RULES FOR POWERSHELL REMOTING
- Log in to the Windows Azure portal using your subscription credentials.
- Click on the existing network security group. In this demo, it’s az-networksecuritygroup from the dashboard.
- In another way, you can also find the network security group from the Azure service list.
- Click on the Inbound security rules option.
- Click on Add button.
- Now click on Basic.
- 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.
- Repeat the same above steps and add the port 5985 in the NSG group.
- The new rule will be displayed in the Inbound rules list.
FINDING AZURE VM PUBLIC ADDRESS
- From the Azure portal, Click on the Virtual Machines service link.
- Click on the VM to access through PowerShell remoting and select the public IP address.
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.
- It prompted us to configure the WinRM for remote management. Type Y and press Enter.
- Run the winrm quickconfig command to verify the settings.
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 184.108.40.206
- It prompts us for the confirmation. Accept the change by entering Y.
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 220.127.116.11 -Credential Get-Credential
- Provide the Azure VM login credentials and click OK.
- Once the credentials are authenticated successfully, you will get the PowerShell prompt as shown below.
- Type the command hostname to find verify the Azure VM name.
Thanks for reading this blog. We hope it was useful for you to learn about accessing azure VM through PowerShell commands.