1
votes

i have a simple problem including xp,powershell and scheduled tasks.I have a working script that uses powershell 2.0 and scheduled tasks on win7,all i want is to do the same on windows xp.I installed required frameworks and the script is ready on winxp,but i just couldnt make the scheduled task work.I am giving you the installion bat i used on win7 to automativly add the required scheduled task,and expecting to learn how to schedule it same on winxp.

schtasks /delete /tn "PowerIdle" /F  
schtasks /delete /tn "PowerIdleKill" /F  
schtasks /delete /tn "PowerIdleSleep" /F  
schtasks /create /tn "PowerIdle" /tr "powershell -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File \"%~dp0power_script.ps1\"" /sc minute /mo 30 /st 00:00  
schtasks /run /tn "PowerIdle"

Basically i need the same install above (win7) in win xp scheduled tasks.Powershell script is located in the directory below in my computer.

C:\Documents and Settings\Administrator\Desktop\PowerIdleV3\power_script.ps1

Thanks in advance!

Edit: I found a solution:

1) Add a custom program, select C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

2) then change the program line to below C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\PowerIdleV3\power_script.ps1

1
4 years later, thank you for adding your solution.khaverim

1 Answers

0
votes

I’m using this syntax to RUN a scheduled *.ps1 file C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command .\automatedemail1.ps1

AUTOMATEDEMAIL1.PS1
$email="?@?.com"
$subject="Lunch"
$body="back in an hour $(get-date)”

Send-MailMessage -from $email -to $email -subject $subject -body $body -smtpServer esdsmtp –bodyashtml

This syntax RUNs a bat file, which in turns executes a ps job "C:\Documents and Settings\jyoung\testmail1.bat"

TESTMAIL1.BAT powershell.exe -command .\automatedemail1.ps1

AUTOMATEDEMAIL1.PS1
$email="?@?.com"
$subject="Lunch"
$body="back in an hour $(get-date)”

Send-MailMessage -from $email -to $email -subject $subject -body $body -smtpServer     ???smtp –bodyashtml