我有一个 PowerShell 脚本,当直接输入到 PowerShell 中时它可以工作。PowerShell 程序使用快捷方式运行:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"
Run Code Online (Sandbox Code Playgroud)
我在 Windows 任务计划程序中尝试了大约 10 种不同的方法来首先打开上面的快捷方式,然后运行我保存的脚本文件,但它不起作用。它挂在“正在运行”上。
该脚本位于此处:
Z:\Exchange PowerShell\MailboxesApproachingOverQuota.ps1
Run Code Online (Sandbox Code Playgroud)
请注意,可以将脚本内容复制并粘贴到上面的 PowerShell 快捷方式中,它运行得非常好,并将输出通过电子邮件发送给我。
请注意,我使用的 PowerShell 实例来自上面显示的快捷方式,其中已经包含参数 - 因此我很难过在 Task Scheduler 中放置什么内容。
请问有什么帮助吗?
谢谢 :)
编辑当我直接在 CMD 中使用以下内容时:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; &'Z:\Exchange Powershell\MailboxesApproachingOverQuota.ps1'"
Run Code Online (Sandbox Code Playgroud)
我得到:http : //tinypic.com/r/n1fkmg/8
当我使用以下内容时:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; &'Z:\Exchange Powershell\MailboxesApproachingOverQuota.ps1'"
Run Code Online (Sandbox Code Playgroud)
powershell exchange-2007 task-scheduler windows-sbs-2008 shell-scripting