Pirate hunting with PowerShell

Sometimes we have a nice day when we want to defeat evil and make life worse for users. Today’s the day 🙂 – let’s start the hunting!

#madeBy krai.be
$computers=Get-Content '\\host\shares\!scripts\!source\!computers.txt'

foreach($computer in $computers) {
    if(Test-Connection -ComputerName $computer -Count 1 -Quiet) {
        Try {
            Write-host "I searching bad Pirates: $computer" -foreground 'gray'
            $file = Invoke-Command -computerName $computer -ScriptBlock {Get-ChildItem -Path C:\Users -Include *.exe, *.mp3, *.mp4, *.wav -File -Recurse -ErrorAction SilentlyContinue | % { Write-Output $env:COMPUTERNAME $_.FullName }}
            $file >> $reportLog

            Write-host "checked: $computer" -foreground 'green'
            $computer >> $successLog
        } Catch {
            Write-host "error: $computer" -foreground 'red'
            $computer >> $errorLog
    } else {
        Write-host "offline: $computer" -foreground 'yellow'
        $computer >> $unreachableLog


Leave a Reply

Your email address will not be published. Required fields are marked *