Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I made a very simple script to enable Remote Desktop connections on a computer:

# Allow Remote Desktop connections
(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)

# Allow low-secutiry connections
(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0)

Now, I wish to finish it, adding a rule for Remote Desktop into Windows Firewall. How I can accomplish this?

BTW: Using Windows 7

Clarification:

Today I enable Remote Desktop manually via "Remote Settings" on "Control Panel\System and Security\System". Doing this way, Windows automatically adds a Firewall Rule to allow incoming remote desktop connections. Fine.

However, using my script above, this last step is not done. On this very configuration screen Windows shows me a reminder message "You must enable the Windows Firewall exception for Remote Desktop"

The question is exactly that: How I can automate this step? Today I do this manually on every computer I install.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You can use NETSH in PowerShell. To enable the Remote Desktop rule, you can use this command

netsh advfirewall Firewall set rule group="Remote Desktop" new enable=yes
share|improve this answer
    
Perfect! This is exactly what I've looking for. Thank you! –  Junior Dec 23 '09 at 18:59

Well, I'd have so search more since it isn't obvious to me what you need to enable.

Here's one way to access the local firewalls settings from PowerShell:

PS>$fw=new-object -com HNetCfg.FwMgr

That's using COM, you can also just call the command-line netsh also.

share|improve this answer

You could also have a look at this Powerpack for Powergui which is for managing the Windows firewall. It might give you some sample code to play with:

Local Firewall Settings PowerPack

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.