{"id":50859,"date":"2023-04-16T09:29:17","date_gmt":"2023-04-16T08:29:17","guid":{"rendered":"https:\/\/ekiwi-blog.de\/50859\/enable-and-disable-remote-desktop-with-powershell\/"},"modified":"2023-04-16T09:34:04","modified_gmt":"2023-04-16T08:34:04","slug":"enable-and-disable-remote-desktop-with-powershell","status":"publish","type":"post","link":"https:\/\/ekiwi-blog.de\/en\/50859\/enable-and-disable-remote-desktop-with-powershell\/","title":{"rendered":"Enable and disable Remote Desktop with PowerShell"},"content":{"rendered":"<p>There are various ways to activate Remote Desktop on a Windows computer. The manual and intuitive way is to go through the settings (<em>Settings &gt; System &gt; Remote Desktop<\/em>). However, there are situations where you want to automate the activation and deactivation of Remote Desktop, for example because you want to roll it out to many different computers or because the activation or deactivation is a component in a script (<em>*.ps1<\/em>) of many other instructions. The following shows the required commands (<em>cmdlet<\/em>) including parameters to enable or disable Remote Desktop.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of content<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi-blog.de\/en\/50859\/enable-and-disable-remote-desktop-with-powershell\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi-blog.de\/en\/50859\/enable-and-disable-remote-desktop-with-powershell\/#Activating_Remote_Desktop_with_PowerShell\" >Activating Remote Desktop with PowerShell<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ekiwi-blog.de\/en\/50859\/enable-and-disable-remote-desktop-with-powershell\/#Disabling_Remote_Desktop_with_PowerShell\" >Disabling Remote Desktop with PowerShell<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>A Windows computer with administrator rights<\/li>\n<li>PowerShell installed on your computer (available by default on Windows systems)<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Activating_Remote_Desktop_with_PowerShell\"><\/span>Activating Remote Desktop with PowerShell<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<figure id=\"attachment_50852\" aria-describedby=\"caption-attachment-50852\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-50852\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/run-powershell-as-admin.jpg\" alt=\"Screenshot Launch Powershell via Windows menu as admin\" width=\"651\" height=\"426\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/run-powershell-as-admin.jpg 651w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/run-powershell-as-admin-300x196.jpg 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><figcaption id=\"caption-attachment-50852\" class=\"wp-caption-text\">Type in Windows searcher PowerShell and launch as admin<\/figcaption><\/figure>\n<ol>\n<li>Open PowerShell with administrator privileges:\n<ul>\n<li>Click on <strong>Start<\/strong>, search for &#8220;<strong>PowerShell<\/strong>&#8220;, right-click on &#8220;Windows PowerShell&#8221; and select &#8220;<strong>Run as Administrator<\/strong>&#8220;.<\/li>\n<\/ul>\n<\/li>\n<li>Activate the <a title=\"Establish Remote Desktop Connection via SSH\" href=\"https:\/\/ekiwi-blog.de\/en\/50644\/rdp-tunnelling-with-ssh\/\">Remote Desktop<\/a> feature by typing the following command and pressing Enter:\n<pre><code><span style=\"color: #ff6600;\">Set-ItemProperty<\/span> -path <span style=\"color: #0000ff;\">'HKLM:\\System\\CurrentControlSet\\Control\\Terminal Server'<\/span> -name <span style=\"color: #0000ff;\">\"fDenyTSConnections\"<\/span> -value 0<\/code><\/pre>\n<\/li>\n<li>It worked the same way for me. But you may still need to adjust the firewall rules. This can be done with the following command:\n<pre><code><span style=\"color: #ff6600;\">Enable-NetFirewallRule<\/span> -DisplayGroup <span style=\"color: #0000ff;\">'Remote Desktop'<\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n<figure id=\"attachment_50844\" aria-describedby=\"caption-attachment-50844\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-50844\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/activate-remote-desktop-via-powershell.jpg\" alt=\"Screenshot PowerShell turn on Remote desktop connection\" width=\"650\" height=\"216\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/activate-remote-desktop-via-powershell.jpg 650w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/activate-remote-desktop-via-powershell-300x100.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><figcaption id=\"caption-attachment-50844\" class=\"wp-caption-text\">Enable Remote Desktop with PowerShell cmdlet<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Disabling_Remote_Desktop_with_PowerShell\"><\/span>Disabling Remote Desktop with PowerShell<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Open <a title=\"Starting and Stopping SSH Server with Powershell\" href=\"https:\/\/ekiwi-blog.de\/en\/50830\/start-ssh-server-with-powershell-windows\/\">PowerShell<\/a> with administrator privileges as described in step 1 above.<\/li>\n<li>Disable the remote desktop feature by typing the following command and pressing Enter:\n<pre><code><span style=\"color: #ff6600;\">Set-ItemProperty<\/span> -Path <span style=\"color: #0000ff;\">'HKLM:\\System\\CurrentControlSet\\Control\\Terminal Server'<\/span> -name <span style=\"color: #0000ff;\">\"fDenyTSConnections\"<\/span> -value 1<\/code><\/pre>\n<\/li>\n<li>Once again, disable the associated firewall rules as required:\n<pre><code><span style=\"color: #ff6600;\">Disable-NetFirewallRule<\/span> -DisplayGroup <span style=\"color: #0000ff;\">'Remote Desktop'<\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n<figure id=\"attachment_50848\" aria-describedby=\"caption-attachment-50848\" style=\"width: 653px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-50848\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/deactivate-remote-desktop-via-powershell.jpg\" alt=\"Screenshot PowerShell disable remote desktop connection\" width=\"653\" height=\"239\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/deactivate-remote-desktop-via-powershell.jpg 653w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/04\/deactivate-remote-desktop-via-powershell-300x110.jpg 300w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><figcaption id=\"caption-attachment-50848\" class=\"wp-caption-text\">Disable remote desktop with PowerShell cmdlet<\/figcaption><\/figure>","protected":false},"excerpt":{"rendered":"<p>There are various ways to activate Remote Desktop on a Windows computer. The manual and intuitive way is to go<\/p>\n","protected":false},"author":2,"featured_media":6031,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1555],"tags":[1711,1598,1992,2869,2872,1602,2911,2068],"class_list":["post-50859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-en","tag-automation-en","tag-network","tag-powershell","tag-remote-access","tag-remote-desktop-en","tag-security-en","tag-system-administration","tag-windows-en-2"],"_links":{"self":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/50859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/comments?post=50859"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/50859\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media\/6031"}],"wp:attachment":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media?parent=50859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/categories?post=50859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/tags?post=50859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}