- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to block ports on the Windows Operating System using PowerShell?
To block the port using PowerShell on the Windows OS, we need to change the firewall settings using the New-NetFirewallRule command.
Example
We need to block the port 5985 on the computer. The below code will block all TCP Incoming requests on the 5985 port on the local computer.
New-NetFirewallRule -DisplayName "Block WINRM HTTP Port" ` -Direction Inbound ` -LocalPort 5985 ` -Protocol TCP ` -Action Block
To block the multiple ports we just need to provide multiple ports in -LocalPort parameter.
New-NetFirewallRule -DisplayName "Block WINRM HTTP/S Ports" ` -Direction Inbound ` -LocalPort 5985,5986 ` -Protocol TCP ` -Action Block
To block ports on the remote computers, you can use the Invoke-Command cmdlet. Make sure the remote computer is reachable and can access the WINRM service and port.
Invoke-Command -ComputerName Test1-Win2k12 -ScriptBlock{ New-NetFirewallRule -DisplayName "Block web ports" ` -Direction Outbound ` -LocalPort 80,8080 ` -Protocol TCP ` -Action Block }
- Related Articles
- How to open a port in the Windows Operating System using PowerShell?
- How to add users and groups to the local groups on Windows System using PowerShell?
- How to retrieve the Operating system of the Azure VM using PowerShell?
- How to delete the local group from the windows system using PowerShell?
- How to Install the Azure CLI on Windows using PowerShell?
- How did the Windows operating system evolve and compare Windows 10 and Ubuntu?
- How to enable credssp authentication on windows server using PowerShell?
- How to check if remote ports are open using PowerShell?
- Difference Between Linux and Windows Operating System
- Advantages and Disadvantages of Windows Operating System
- How to delete the windows certificate using PowerShell?
- How to Get Windows features using PowerShell?
- How to remove windows features using PowerShell?
- How to enable or disable local user on Windows OS using PowerShell?
- How to get the Windows certificate details using PowerShell?

Advertisements