From 4367ee7a8f24eb0956c35fbd41f1df0d02b60edb Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sun, 25 Mar 2018 22:33:06 +0200 Subject: [PATCH] Implement FwBlockProgram() --- cleanW10.ps1 | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cleanW10.ps1 b/cleanW10.ps1 index f2121c9..9206291 100755 --- a/cleanW10.ps1 +++ b/cleanW10.ps1 @@ -99,7 +99,35 @@ function FwBlockProgram { )] [object]$params ) - Write-Host " Test" + if ( $params.ContainsKey('file') ) { + foreach ($line in Get-Content $params.file ){ FwBlockOutputIP @{"ip"="$line"} } + } + elseif ( $params.ContainsKey('path') ) { + $path = Invoke-Expression """$($params.path)""" + Write-Host -NoNewline "`tBlock program $($path) : " + if ( -not (Test-Path $path) ) { + Write-Host -Foregroundcolor Red "Error (path not found)" + return + } + if ( -not $params.ContainsKey('name') ) { + $params.name = $params.path + } + if ( Get-NetFirewallRule -Name $($params.name) -ErrorAction SilentlyContinue) { + Write-Host -ForegroundColor Yellow "already blacklisted" + return + } + try { + New-NetFirewallRule -Name "$($params.name)" -DisplayName "$($params.name)" -Program "$path" -Direction Outbound -Protocol any -Enabled True -Profile Any -RemoteAddress any -Action Block | Out-Null + Write-Host -ForegroundColor Green "done" + } + catch { + Write-Host -ForegroundColor Red "error" + return + } + } + else { + Write-Host -ForegroundColor Red "`tError : No path or file for action $($MyInvocation.MyCommand.Name)" + } } function RemoveScheduledTask () {