On lines 19 & 20 I am trying to get the Device and drive that is alerting and kicking off the PowerShell script to tell us the top 10 largest files.
2 questions how do I get the parameters from the alert and how do I get PRTG to execute the script on drive sensors that are "Down" and not in a warning?
Any help would be appreciated.
$scriptBlock = { param ([string]$Path) #$ErrorActionPreference = "silentlyContinue" $list = New-Object 'Collections.ArrayList' $files =(robocopy /bytes /njh /njs /np /nc /fp /ndl /l /s "$Path" 'NoDestination') foreach($file in $files) { $data = $file.split("`t") $null = $list.add([tuple]::create([uint64]$data[3], $data[4])) } $list.sort() # sort by size ascending $result = $list.GetRange($list.count-10,10) $result #| select item2, item1 | sort item1 -Descending } $device = %Device $DriveAlerting = %sensor # needs to b einthe format "D:\" $result= Invoke-Command -ComputerName $device -ScriptBlock $scriptBlock -ArgumentList $DriveAlerting $mailOutput =$result | select -property @{N='Device';E={$_.PSComputerName}}, @{N='Path';E={$_.Item2}}, @{N='Size in GB';E={($_.Item1/1GB)}} | sort 'Size in GB' -Descending #### Create the email $msg = New-Object Net.Mail.MailMessage $style = "<style>BODY{font-family: Arial; font-size: 10pt;}" $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}" $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }" $style = $style + "TD{border: 1px solid black; padding: 5px; }" $style = $style + "</style>" $Msg = @{ To = xxxxxxxx From = XXXXXXXX Body = $mailOutput | ConvertTo-Html -Head $Style -Body "<H2>Top 10 largest files</H2>" | Out-String # subject = "$device - $((Get-Date).ToShortDateString())" SmtpServer = xxxxxxx BodyAsHtml = $True } Send-MailMessage @Msg
Add comment