diff --git a/cleanW10.ps1 b/cleanW10.ps1 old mode 100755 new mode 100644 index d9c45ed..49f132d --- a/cleanW10.ps1 +++ b/cleanW10.ps1 @@ -16,36 +16,31 @@ function blockShittyHost { remove-host $filename $hostname Write-Host -NoNewline -ForegroundColor White "Block shitty host $hostname" 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 { Write-Host -ForegroundColor Red " Error " return } - Write-Host -ForegroundColor Green " OK " + Write-Host -ForegroundColor Green " done " } -function remove-host { +function is_host_present { param([string]$filename, [string]$hostname) $c = Get-Content $filename - $newLines = @() foreach ($line in $c) { $bits = [regex]::Split($line, "\t+") - if ($bits.count -eq 2) { - if ($bits[1] -ne $hostname) { - $newLines += $line - } - } else { - $newLines += $line + if ($bits[1] -eq $hostname) { + return $true } } - - # Write file - Clear-Content $filename - foreach ($line in $newLines) { - $line | Out-File -encoding ASCII -append $filename - } + return $false } function remove_shittyTasks () { @@ -162,10 +157,10 @@ Write-Output "I's time to kick ass and chew bubble gum" Write-Output "________________________________________" write-Output "" -$shittyFeatures | foreach { disableShitty $_ } -$shittyServices | Foreach { disableShittyService $_ } -$shittyModernApp | Foreach { disableModernShitty $_ } -$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ } +#$shittyFeatures | foreach { disableShitty $_ } +#$shittyServices | Foreach { disableShittyService $_ } +#$shittyModernApp | Foreach { disableModernShitty $_ } +$shittyHosts | Foreach { blockShittyHost $HOST_FILE $HOST_IP $_ } remove_shittyTasks $shittyTasks $shittyIP | Foreach {