Improve blockShittyhost function
This commit is contained in:
parent
7371507fd4
commit
278232165e
1 changed files with 15 additions and 20 deletions
35
cleanW10.ps1
Executable file → Normal file
35
cleanW10.ps1
Executable file → Normal file
|
@ -16,36 +16,31 @@ function blockShittyHost {
|
||||||
remove-host $filename $hostname
|
remove-host $filename $hostname
|
||||||
Write-Host -NoNewline -ForegroundColor White "Block shitty host $hostname"
|
Write-Host -NoNewline -ForegroundColor White "Block shitty host $hostname"
|
||||||
try {
|
try {
|
||||||
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $filename
|
if ( ! $(is_host_present $filename $hostname) ){
|
||||||
|
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $filename
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host -NoNewline -ForegroundColor Yellow " Already blocked "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host -ForegroundColor Red " Error "
|
Write-Host -ForegroundColor Red " Error "
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Write-Host -ForegroundColor Green " OK "
|
Write-Host -ForegroundColor Green " done "
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove-host {
|
function is_host_present {
|
||||||
param([string]$filename, [string]$hostname)
|
param([string]$filename, [string]$hostname)
|
||||||
$c = Get-Content $filename
|
$c = Get-Content $filename
|
||||||
$newLines = @()
|
|
||||||
|
|
||||||
foreach ($line in $c) {
|
foreach ($line in $c) {
|
||||||
$bits = [regex]::Split($line, "\t+")
|
$bits = [regex]::Split($line, "\t+")
|
||||||
if ($bits.count -eq 2) {
|
if ($bits[1] -eq $hostname) {
|
||||||
if ($bits[1] -ne $hostname) {
|
return $true
|
||||||
$newLines += $line
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$newLines += $line
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $false
|
||||||
# Write file
|
|
||||||
Clear-Content $filename
|
|
||||||
foreach ($line in $newLines) {
|
|
||||||
$line | Out-File -encoding ASCII -append $filename
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_shittyTasks () {
|
function remove_shittyTasks () {
|
||||||
|
@ -162,10 +157,10 @@ Write-Output "I's time to kick ass and chew bubble gum"
|
||||||
Write-Output "________________________________________"
|
Write-Output "________________________________________"
|
||||||
write-Output ""
|
write-Output ""
|
||||||
|
|
||||||
$shittyFeatures | foreach { disableShitty $_ }
|
#$shittyFeatures | foreach { disableShitty $_ }
|
||||||
$shittyServices | Foreach { disableShittyService $_ }
|
#$shittyServices | Foreach { disableShittyService $_ }
|
||||||
$shittyModernApp | Foreach { disableModernShitty $_ }
|
#$shittyModernApp | Foreach { disableModernShitty $_ }
|
||||||
$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ }
|
$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ }
|
||||||
remove_shittyTasks $shittyTasks
|
remove_shittyTasks $shittyTasks
|
||||||
|
|
||||||
$shittyIP | Foreach {
|
$shittyIP | Foreach {
|
||||||
|
|
Reference in a new issue