
$allowden圜hoice = $Host.UI. $dirChoice = $Host.UI.PromptForChoice('Traffic Flow','Enter Traffic Flow direction (inbound/outbound): ',('&inbound','&outbound'),0) $protchoice = $Host.UI.PromptForChoice('Protocol Type','Enter Protocol (TCP/UDP): ',('&TCP','&UDP'),0) $portNumber = Read-Host -Prompt "Enter Port Number: " $rulename = Read-Host -Prompt "Enter rule name: " Here is another way of creating ports on Firewall, with the benefit that, the system will prompt you for all the options relating to inbound/outbound, protocol, allow/deny etc. $fwMgr = New-Object -ComObject HNetCfg.FwMgr $port1.Name = 'MyTestPort' # name of Port Now, right-click on CMD and Run as Administrator. The first thing you want to do is open the Start Menu and search for CMD. $port1 = New-Object -ComObject HNetCfg.FWOpenPort The good news is that Windows has a pretty useful command built into it that will show you what ports are currently being used on your computer by various applications and services. #$numberAsString = read-host "type an port number" # Creates a rule to open an incomming port in the firewall.

If you absolutely must use Powershell, you can use something like the script below(for the port 80 as well): #=

You can use this command from the Powershell level. The command to open port 80 is: netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80
