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 () {