We used to have Orion run this on a remote server where the PS was
located. It used the notification information for $Server (hostname) and
$ Drive$ to delete files on a 3rd server that had the full drive. When I
attempt to create a workflow, it appears the PS needs to be on the
local machine running opmanager. While this shouldn't be a problem, I
am having difficulty trying to figure out the $Server and $Drive$ (Param)
part and how to have it execute properly, as well as setting up the
Check Drive Free Space to trigger it.
Here is the main body of the script that does the work, the rest of the script is to send an email out so I didn't add that.
Param([string]$Server, [string]$Drive)
$myDays = -30
$myNum = 0
$myCount = 0
$myPath = "\\$Server\$Drive$\Placeholders"
Write-Host "$Server - $Drive - $myPath"
$currDate = Get-Date
$myDate = $currDate.AddDays($myDays)
$cleanDate = $myDate.ToString("MM/dd/yyyy")
$mailDate = $currDate.toString("MM/dd/yyyy")#
$myFiles = Get-ChildItem -Path $myPath
Write-Host $myFiles.Count
If ($myFiles.Count -gt 10) {
$myNum = 10
}
Else {
$myNum = ($myFiles.Count - 1)
}
ForEach ($File in $myFiles) {
If ($File.Name -like '*deleteme*' -and $myCount -lt $myNum) {
remove-item -path $File.FullName -force
$myCount++
}
}
Also where on the server do I put the PS script so it can be executed?