First I admit this may be a long shot, but was hoping that someone could provide either thoughts on how find the root cause or a “yeah I’ve seen that before!” kind of insight.
I have a script that on the surface is fairly simple, and I’d say 99.9% of the time it runs without a hitch.
General outline of the script is that it is run as a scheduled task, once daily.
- At startup it queries our SQL server for a current list of active jobs. into: $CurrentJobList
- It then imports the CSV file output from the last run of active jobs into: $PrevJobList
- I then use the compare-object function to compare one column "name", capturing the result as: $MisMatches
- If $MisMatches is true I will, pipe $CurrentJobList to Export-CSV into two files (one for upload to a service, the second as the reference list that will be used on next run).
When it doesn’t work correctly both 'exported CSV files seem to include the results of the $MisMatches variable which causes problems specifically because the $MisMatches variable includes the “SideIndictator” column, which messes up the file for the external service.
I’ve checked my code and cannot find any operation that would “write” to the variable. I’m assuming that while the script is running some event on the host interferes with the running process?
- Host information
- Server 2012 r2
- PS host version: 5.1.14409.1018
- Sophos Endpoint AV
- also serves as PRTG network monitoring server
151. $CurrentJobList = get-JobList -SqlConnection $conn
153. $script:Result += "`r`nCurrent Job List:`r`n" + $($CurrentJobList.Name -join "`r`n")
159. $MisMatches = Compare-Object $PrevJobList $CurrentJobList -Property name -PassThru
180. $CurrentJobList | Export-Csv $($ExportPath + 'Certify-DimensionFile.csv') -NoTypeInformation -Force
191. $CurrentJobList | Export-Csv $($ExportPath + 'PSjobList.csv')Thanks for any insight, you might be able to provide!