简体   繁体   中英

Powershell Script via Task Scheduler Not Working with Arguments

I'm hoping you geniuses can help me out today. I'm not a savant with PowerShell, I only use it to automate some tasks to make life easier. The one thing I'm trying to automate is a daily password reminder to those employees whose password will be expiring within 14 days. The script I wrote (NewPasswordChange.ps1) works flawlessly when I run it via PowerShell, but will not run when put into Task Scheduler. Please let me know what I'm doing wrong.

Action: Start a program Program/Script: C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe

Add Arguments: -File 'NewPasswordChange.ps1' -smtpServer 'COMPANY-com.mail.protection.outlook.com' -expireInDays '14' -from 'IT Support it_support@COMPANY.com' -Logging -LogPath 'c:\\logFiles'

Only powershell understands the single-quotes. When used from a regular command line 'IT Support it_support@COMPANY.com' for example will be interpreted as 3 arguments:

  1. 'IT
  2. Support
  3. it_support@COMPANY.com'

Use double quotes instead:

-File "NewPasswordChange.ps1" -SmtpServer "COMPANY-com.mail.protection.outlook.com" -ExpireInDays 14 -From "IT Support it_support@COMPANY.com" -Logging -LogPath "c:\logFiles"

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.

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