[英]Powershell script does not run via Task Scheduler
PowerShell script runs fine manually, but doesn't run in Task scheduler. PowerShell 脚本手动运行良好,但不在任务调度程序中运行。 The script:
剧本:
$env:CLIENTNAME | Out-File C:\Users\tst5clj\Desktop\folder\log.txt -Append
I tried another command($env:COMPUTERNAME) and works fine both manually and via PowerShell.我尝试了另一个命令($env:COMPUTERNAME),并且手动和通过 PowerShell 都可以正常工作。
If you want to run a.ps1 script from a scheduled task, your task's action should be configured as follows (at a minimum)如果您想从计划任务运行 a.ps1 脚本,您的任务操作应配置如下(至少)
And your script.ps1 can run whatever code you need.您的 script.ps1 可以运行您需要的任何代码。
# Setup for example
$env:CLIENTNAME = 'Contoso'
$env:CLIENTNAME | Out-File "$PSScriptRoot\log.txt"
Here's a similar Q&A: How to execute PowerShell script on Task Scheduler?这是一个类似的问答: 如何在任务计划程序上执行 PowerShell 脚本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.