首页 文章

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

提问于
浏览
1

我有一个简单的问题,包括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"

基本上我需要在win xp预定任务中使用相同的安装(win7).Powershell脚本位于我的计算机下面的目录中 .

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

提前致谢!

编辑:我找到了一个解决方案:

1)添加自定义程序,选择 C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

2)然后将程序行更改为 C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\PowerIdleV3\power_script.ps1 以下

1 回答

  • 0

    我正在使用此语法来运行计划的* .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
    

    此语法运行bat文件,该文件又执行ps作业“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
    

相关问题