NetSh | blockinbound,allowoutbound | work on local not on remote

I have a mixed environment of 2008 /R2 and 2012 /R2

I am need to block blockinbound (default) traffic and allow all outbound traffic. I have written this if-else statement the evaluated the PowerShell version to determine either to run a NetSecurity cmdlet or a NetSh advfirewall.

The issue am having is with the netsh command. I works on local computer but will not on remote. Has anyone ran into this or is there a solution or am I doing something wrong?

Below is my process block with my - else code wrapped on a sriptblock


Invoke-Command -Session $Servers -ScriptBlock {
if ($PSVersionTable.PSVersion.Major -gt 3){
Set-NetFirewallProfile `
-DefaultInboundAction Block `
-DefaultOutboundAction Allow
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound

if($PSVersionTable.PSVersion.Major -gt 3){
Get-NetFirewallProfile -all | Select-Object Enabled,Name,LogAllowed,LogIgnored,LogFileName
#Show rule status
netsh advfirewall show allprofiles




When you say not working, are you getting any error or it just executes and do nothing ?

It returns that the command was incorrect but the same command works on local firewall.

After much I have found the solution to my problem.

The NetSh help file content shows this command as an example

[pre]netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound[/pre]

It dose not work on a PSSession in a remote computer.

This is what worked on a remote computer.

[pre]netsh advfirewall set allprofiles firewallpolicy “blockinbound,allowoutbound”[/pre]

The blockinbound and allowinbound has to be in an open and closing quotation mark


Good that you worked it all out, but as a rule passing multiples to certain commands, require proper quoting for success.

Running external commands, always require special consideration.

Why are you not using the built-in firewall cmdlets vs netsh?

CommandType Name                                                             Version      Source                          
----------- ----                                                             -------      ------                          
Function    Copy-NetFirewallRule                                         NetSecurity                     
Function    Disable-NetFirewallRule                                      NetSecurity                     
Function    Enable-NetFirewallRule                                       NetSecurity                     
Function    Get-NetFirewallAddressFilter                                 NetSecurity                     
Function    Get-NetFirewallApplicationFilter                             NetSecurity                     
Function    Get-NetFirewallInterfaceFilter                               NetSecurity                     
Function    Get-NetFirewallInterfaceTypeFilter                           NetSecurity                     
Function    Get-NetFirewallPortFilter                                    NetSecurity                     
Function    Get-NetFirewallProfile                                       NetSecurity                     
Function    Get-NetFirewallRule                                          NetSecurity                     
Function    Get-NetFirewallSecurityFilter                                NetSecurity                     
Function    Get-NetFirewallServiceFilter                                 NetSecurity                     
Function    Get-NetFirewallSetting                                       NetSecurity                     
Function    New-NetFirewallRule                                          NetSecurity                     
Function    Remove-NetFirewallRule                                       NetSecurity                     
Function    Rename-NetFirewallRule                                       NetSecurity                     
Function    Set-NetFirewallAddressFilter                                 NetSecurity                     
Function    Set-NetFirewallApplicationFilter                             NetSecurity                     
Function    Set-NetFirewallInterfaceFilter                               NetSecurity                     
Function    Set-NetFirewallInterfaceTypeFilter                           NetSecurity                     
Function    Set-NetFirewallPortFilter                                    NetSecurity                     
Function    Set-NetFirewallProfile                                       NetSecurity                     
Function    Set-NetFirewallRule                                          NetSecurity                     
Function    Set-NetFirewallSecurityFilter                                NetSecurity                     
Function    Set-NetFirewallServiceFilter                                 NetSecurity                     
Function    Set-NetFirewallSetting                                       NetSecurity                     
Function    Show-NetFirewallRule                                         NetSecurity                     

# Get parameters, examples, full and Online help for a cmdlet or function

# get function / cmdlet details
(Get-Command -Name Get-NetFirewallProfile).Parameters
Get-help -Name Get-NetFirewallProfile -Examples
Get-help -Name Get-NetFirewallProfile -Full
Get-help -Name Get-NetFirewallProfile -Online

# Get parameter that accepts pipeline input
Get-Help Get-NetFirewallProfile -Parameter * | 
Where-Object {$_.pipelineInput -match 'true'} | 
Select * 

# List of all parameters that a given cmdlet supports along with a short description:
Get-Help Get-NetFirewallProfile -para * | 
Format-Table Name, { $_.Description[0].Text } -wrap

Get-Help about_*
Get-Help about_Functions