To open port on Windows Server firewall I am using this command:
netsh advfirewall firewall add rule name="My rule name port 12345" dir=in action=allow protocol=TCP localport=12345
For port close the command is like that:
netsh advfirewall firewall delete rule name="My rule name port 12345"
That's all.
Link to Microsoft article is here.