Implement FwBlockProgram()
This commit is contained in:
parent
1dbac1b138
commit
4367ee7a8f
1 changed files with 29 additions and 1 deletions
30
cleanW10.ps1
30
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 () {
|
||||
|
|
Reference in a new issue