Mike, really appreciate posting this script, but need your help with something. We're having problems running the script as a Scheduled Task. We want to execute it hourly to gather statistics using the Gather switch. Running it from the shell and from the command line work great (powershell -file "<path to script>" -Gather -WorkingDirectory "<directory path>"), but when running it as a Scheduled Task, the LogStats.csv file is written but doesn't populate the data from the databases; it only writes the header line. A quick look at the task History shows Action and Task completed with an Operational Code "2". Suspect there is a problem with the task "seeing" the TargetServers.txt file. We're running the task as system, but have tried an account with all proper permissions with the same results.
Any assistance you can provide would be greatly appreciated!