Y
YuryVo
I'm trying to set up a scheduled task in Windows Server 2012 that will periodically save all events in Event Viewer log into a text file. I've put together a command that works well when run in the Windows command prompt:
powershell Get-WinEvent -FilterXML ([xml] (Get-Content "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNow.xml")) > "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog.txt"
This command takes events selected by the filter defined in Sugar2SvcNow.xml file and saves them in a text file called Sugar2SvcNowLog.txt. Next I created a job in Task Scheduler where the Action is to run C:\Windows\System32\cmd.exe with the following arguments:
'powershell Get-WinEvent -FilterXML ([xml] (Get-Content "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNow.xml")) > "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog.txt"'
In other words, the arguments are the exact command that worked well in the command prompt. When I run this job, the status is shown as "task is currently running", but then it never completes and stays permanently as "currently running". The text file with the log is not created. No errors are displayed. It seems that the command must be formatted differently in the Task Scheduler than in the command prompt. What do I need to change to make it work?
Continue reading...
powershell Get-WinEvent -FilterXML ([xml] (Get-Content "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNow.xml")) > "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog.txt"
This command takes events selected by the filter defined in Sugar2SvcNow.xml file and saves them in a text file called Sugar2SvcNowLog.txt. Next I created a job in Task Scheduler where the Action is to run C:\Windows\System32\cmd.exe with the following arguments:
'powershell Get-WinEvent -FilterXML ([xml] (Get-Content "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNow.xml")) > "C:\Users\yvoloshin_pdadmin\Desktop\Sugar2SvcNowLog.txt"'
In other words, the arguments are the exact command that worked well in the command prompt. When I run this job, the status is shown as "task is currently running", but then it never completes and stays permanently as "currently running". The text file with the log is not created. No errors are displayed. It seems that the command must be formatted differently in the Task Scheduler than in the command prompt. What do I need to change to make it work?
Continue reading...