PowerShell script runs fine manually, but doesn't run in Task scheduler. 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.
If you want to run a.ps1 script from a scheduled task, your task's action should be configured as follows (at a minimum)
And your script.ps1 can run whatever code you need.
# 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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.