微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

How Do I Open Ports with PowerShell?

How Do I Open Ports with PowerShell?

If you have a history with Windows,you're probably used to using netsh to open ports on the Windows Firewall. We have a whole slew of PowerShell cmdlets to administer the Windows Firewall Now and I wondered how to use PowerShell to open ports. It took me longer than it should have to do it,so I thought I'd share. In the end it is simple,but there are a lot of cmdlets to wade through,which is where I got hung up.

Here is what you'd do with netsh to open ports 80 and 443:

netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80
netsh advfirewall firewall add rule name="Open Port 443" dir=in action=allow protocol=TCP localport=443


Here is how you'd open the same ports for only the Domain and Private profiles (not Public) with PowerShell:

New-NetFirewallRule -displayName 'HTTP(S) Inbound' -Profile @('Domain','Private') -Direction Inbound -Action Allow -Protocol TCP -LocalPort @('80','443')

References
PowerShell cmdlets to manage the Windows firewall
Netsh Examples

 

原文地址:https://blog.csdn.net/allway2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐