Skip to content

Instantly share code, notes, and snippets.

@ilsubyeega
Last active April 3, 2023 02:14
Show Gist options
  • Select an option

  • Save ilsubyeega/f3257879c6987821801b5b43da02313b to your computer and use it in GitHub Desktop.

Select an option

Save ilsubyeega/f3257879c6987821801b5b43da02313b to your computer and use it in GitHub Desktop.
$content = Get-Content .\Desktop\list.txt.txt
$content = $content.Trim()
foreach ($item in $content.Split("`n"))
{
if ($null -eq $item -or $item.Length -eq 0) { return }
$splitted = $item.Split("|")
$rule_name = $splitted[0].Trim()
$rule_location = $splitted[1].Trim()
New-NetFirewallRule -DisplayName $rule_name -Direction Inbound -Program $rule_location -Action Block
New-NetFirewallRule -DisplayName $rule_name -Direction Outbound -Program $rule_location -Action Block
Write-Host "Successfully add rule" $rule_name "(" $rule_location ")"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment