通过任务计划程序的 Powershell 脚本无法使用参数

问题描述 投票:0回答:1

我希望你们今天能帮助我。我不是 PowerShell 专家,我只是用它来自动执行一些任务,以使生活更轻松。我试图自动化的一件事是每天向密码将在 14 天内过期的员工发出密码提醒。我编写的脚本 (NewPasswordChange.ps1) 在通过 PowerShell 运行时完美运行,但在放入任务计划程序时无法运行。请让我知道我做错了什么。

操作:启动程序 程序/脚本: C:\Windows\System32\WindowsPowerShell 1.0\powershell.exe

添加参数: -File 'NewPasswordChange.ps1' -smtpServer 'COMPANY-com.mail.protection.outlook.com' -expireInDays '14' -from 'IT 支持 [电子邮件受保护]' -Logging -LogPath ' c:\logFiles'

powershell arguments windows-task-scheduler
1个回答
0
投票

只有 powershell 能够理解单引号。例如,当从常规命令行使用时,

'IT Support [email protected]'
将被解释为 3 个参数:

  1. 'IT
  2. Support
  3. [email protected]'

使用双引号代替:

-File "NewPasswordChange.ps1" -SmtpServer "COMPANY-com.mail.protection.outlook.com" -ExpireInDays 14 -From "IT Support it_supp[email protected]" -Logging -LogPath "c:\logFiles"
© www.soinside.com 2019 - 2024. All rights reserved.