Running a Powershell script in Task Scheduler not producing results

Y

YuryVo

I'm trying to run a Powershell script file as a Scheduled Task in Windows Server 2012. The script selects events in Event Viewer using an xml filter and saves them into a text file. The script file is named Sugar2SvcNowLog.ps1 and contains this text:

Get-WinEvent -FilterXml ([xml] (Get-Content "Desktop\Sugar2SvcNow.xml")) | format-table ProviderName, TimeCreated, Id, LevelDisplayName, message -wrap -autosize | Out-File -FilePath "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog $(get-date -f yyyy-MM-dd_HHmmss).txt"

This script creates a text file exactly as intended when I run it in the Windows Command Prompt like this:

powershell -file "C:\Users\yvoloshin_pdadmin\Desktop\
Sugar2SvcNowLog.ps1"

Then, I've set up a Task Scheduler job where the program to run was set as "powershell" and the arguments are

-file "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog.ps1"
When the job runs, the status is shown as "the operation completed successfully". But, a text file is not generated. How can the operation be completed successfully if the file is not generated? What should I do differently?

Continue reading...
 
Back
Top Bottom