Implement FwBlockProgram()

This commit is contained in:
Yorick Barbanneau 2018-03-25 22:33:06 +02:00
parent 1dbac1b138
commit 4367ee7a8f

View file

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