简体   繁体   English

在XP上将Powershell 2.0脚本作为计划任务

[英]Powershell 2.0 script as scheduled task on XP

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. 我有一个简单的问题,包括XP,PowerShell和计划任务。我有一个工作脚本,该脚本在Win7上使用PowerShell 2.0和计划任务,我只想在Windows XP上做同样的事情。我安装了必需的框架,并且脚本已准备就绪winxp,但我只是无法使计划的任务正常工作。我给你我在win7上使用的安装棒自动添加所需的计划任务,并希望学习如何在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. 基本上,我需要在win xp计划任务中进行与上述(win7)相同的安装.Powershell脚本位于计算机下方的目录中。

C:\\Documents and Settings\\Administrator\\Desktop\\PowerIdleV3\\power_script.ps1 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 1)添加一个自定义程序,选择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 2)然后将程序行更改为C:\\ WINDOWS \\ system32 \\ WindowsPowerShell \\ v1.0 \\ powershell.exe -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\\ PowerIdleV3 \\ power_script.ps1

I'm using this syntax to RUN a scheduled *.ps1 file C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -command .\\automatedemail1.ps1 我正在使用此语法来运行计划的* .ps1文件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" 此语法运行一个bat文件,该文件依次执行ps作业“ C:\\ Documents and Settings \\ jyoung \\ testmail1.bat”

TESTMAIL1.BAT powershell.exe -command .\\automatedemail1.ps1 TESTMAIL1.BAT powershell.exe-命令。\\ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM