TL;DR — Résumé Rapide

Learn re-enable remote desktop with powershell after you've blocked it with your own firewall rule. How to: Re-enable Remote Desktop with <

Note : Cet article a été publié à l’origine en 2013. Certaines étapes, commandes ou versions de logiciels ont pu changer. Consultez la documentation actuelle de Windows Azure Cloud pour les informations les plus récentes.

Prérequis

Avant de commencer, assurez-vous d’avoir :

  • Windows Server 2012 or 2012 R2
  • Administrator privileges
  • Server Manager access

How to: Re-enable Remote Desktop with (https://www.microsoft.com/powershell “Windows PowerShell”) after you’ve blocked it with your own firewall rule

Obtained from: https://www.hanselman.com/blog/CSIReenablingRemoteDesktopWithPowerShellAfterYouveBlockedItWithYourOwnFirewallRule.aspx   The Big Problem:

I set up an Azure (https://en.wikipedia.org/wiki/Virtual_machine “Virtual machine”) running (https://www.microsoft.com/en-us/server-cloud/windows-server/default.aspx “Windows Server 2012”). I accidentally disabled the Remote Desktop (https://en.wikipedia.org/wiki/Windows_Firewall “Windows Firewall”) rule (while I was remotely connected). The connection dropped as you would expect. I have been pulling my hair out ever since trying to re-enable this rule.

Doh. Ouch. I didn’t ask how this happened, but you know, one gets to clicking and typing and you can feel the mistake about to happen as your hand drops towards the keyboard, but by then it’s too late. Gravity has screwed you. I suggested that Seán use (https://learn.microsoft.com/en-us/magazine/ff700227.aspx). Remote PowerShell is like “(https://en.wikipedia.org/wiki/Secure_Shell “Secure Shell”)” in *nix. You get a remote terminal and can pretty much do whatever you want from there.

TL;DR VERSION OF SEÁN’S EXPERIENCE.

  • Make sure PowerShell is enabled in the Endpoints section of the Azure portal.
  • Get the server’s certificate (PowerShell needs this for remote commands). You can get the server certificate by going to your domains’ (https://en.wikipedia.org/wiki/Uniform_resource_locator “Uniform resource locator”): https://yourdomain.cloudapp.net:12345 (where :12345 is the port that PowerShell uses).
  • Export the SSL certificate of the site as a .CER file and install it on your local machine.
  • Save it to the “Trusted Root Certification Authorities” store on your machine.
  • Open PowerShell with administrative privileges on your local machine and type: Enter-PSSession -ComputerName yourdomain.cloudapp.net -Port 5986 -Credential YourUserName -UseSSL
  • A login popup will appear, enter your VM’s login credentials here.
  • You will now be able to execute commands against the Azure VM. In Seán’s case, he ran netsh advfirewall firewall set rule group="remote desktop" new enable=Yes and exited the PowerShell session and was able to remotely connect to my machine.

LONG DETAILED VERSION WITH SCREENSHOTS

Résumé

Articles Connexes