Select Page

Required Files: None


This will log ports that are listening and alert if they change between script runs.


 

Import-Module $env:SyncroModule
 
$oldFile = "C:\temp\ports-old.txt"
$newFile = "C:\temp\ports-new.txt"
 
if(!(test-path C:\temp)){
  mkdir C:\temp
}
 
$oldFilePresent = Test-Path -Path $oldFile
$newFilePresent = Test-Path -Path $newFile
 
 
if($oldFilePresent -And $newFilePresent){
   del $oldFile
   mv $newFile $oldFile
} 
 
Get-ScheduledTask
 
if($oldFilePresent){
    $tasks = Get-NetTCPConnection | ? {$_.State -eq "Listen"}
    Get-NetTCPConnection | ? {$_.State -eq "Listen"} | out-file $new
    $comparison = compare-object (get-content $newFile) (get-content $oldFile)
    if($comparison){
        $comparison | out-file C:\temp\portsdiff.txt
        rmm-alert -Category "listening_ports_changed" -Body "Windows Listening Ports has changed! check out $(get-content C:\temp\portsdiff.txt)"
    }   
} ELSE {  
    Get-NetTCPConnection | ? {$_.State -eq "Listen"} | out-file $new   
    mv $newFile $oldFile
}