$Version="v8.4.28 Aaron Dodd" $Description="Generate CSV of scheduled tasks in the environment" #------------------------------------------------------------------------------ # Settings / Variables #------------------------------------------------------------------------------ If (Test-Path "QueryScheduledTasks.config") { $cfg=[xml](get-content "QueryScheduledTasks.config") } Else { Write-Host "!! ERROR !! - Config file not found" Write-Host "A file with the same name as this script, ending in .config, must exist in the same directory as this script." exit } $ServerList = Import-Csv $cfg.configuration.ServerList.name $FinalReport=$cfg.configuration.FinalReport.name $TempDir=$cfg.configuration.TempFolder.name $TempReport=$TempDir + "\temp.csv" $ErrorActionPreference=$cfg.configuration.ErrorAction.value #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ # Process tasks #------------------------------------------------------------------------------ ForEach ($Server in $ServerList) { # schtasks /QUERY /S $Server.Name /FO CSV /V > $TempReport #--- Added--- Write-Host $Server.name schtasks /QUERY /S $Server.Name /FO CSV /V | Where {$_.Length -gt 0} | Set-Content $TempReport #------------ $TempCsv += Import-Csv $TempReport } Remove-Item $TempReport $TempCsv | Export-Csv $FinalReport -notype #------------------------------------------------------------------------------