I have a Powershell script that exports a list of all the services on my local computer using the following command:
Get-CimInstance win32_service | Export-Csv $PSScriptRoot\Local\services.csv
It works fine when I run it under a local admin account from a powershell prompt. I tried running it as a scheduled task, using the same local admin account to run the scheduled task, and nothing gets output to the .csv file.
I know the scheduled task itself is running OK, because there are other output files that are being updated as I would expect. What's different about running this script as a scheduled task that is breaking it?
UPDATE: I ran the script both ways with ProcMon running in the background. The one difference I noticed is that the scheduled task's process had a Session ID of 0, where as running the script directly had a Session ID of 4.