1
votes

I have created the following powershell script:

stop-service ''3456''

start-sleep -s 60

stop-service "2354"

start-sleep -s 60

Restart-computer QY34 -Force

send -mailmessage -from operating.system@abc.com -To asdf@abc.com -subject test -attachment 'c:\Temp|test.log' -smtp server "127.0.0.1"

I have entered the following information on windows task scheduler

On Actions Tab;

C:\windows\System32\windowspowershell\v1.0\powershell.exe

Arguments Tab:

-file "c:\scripts\test.ps1"*>"c:\Temp\test.log"

Can anyone please help me in getting the log file while running the script via Task Scheduler?

1
have you tried running that exact line from the console ... the entire line that task scheduler will run likely aint what you think it is. [grin]Lee_Dailey

1 Answers

0
votes

Change the arguments from

-file "c:\scripts\test.ps1"*>"c:\Temp\test.log"

to

 "c:\scripts\test.ps1" *> "c:\Temp\test.log"

and it should work as expected. Note the blank spaces before and afer *>.

I think the problem is that Powershell will read everything after -file as the file input. It'll still work, but as it just stops reading after the "file" bit, the > operator is ignored/not seen. Removing -file Powershell will still find the script using positional parameters, but it will also handle the > operator and output to file.

If you run if from a command line it'll work, I think because cmd.exe will handle the output instead of Powershell in that case, but don't quote me on that bit.