我有一个PowerShell脚本,直接input到PowerShell中。 PowerShell程序使用shorcut运行:
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'"
我已经在Windows任务计划程序中尝试了大约10种不同的方法来首先打开上面的快捷方式,然后运行我保存的脚本文件,但它不会工作。 它挂在“跑步”上。
脚本位于:
Z:\Exchange PowerShell\MailboxesApproachingOverQuota.ps1
请注意,可以将脚本内容复制并粘贴到上面的PowerShell快捷方式中,并且运行得非常好,并按照需要将其输出发送给我。
请注意,我使用的PowerShell实例是从上面显示的快捷方式中已经有参数 – 因此,我难以置信的东西放在哪里在任务计划。
请帮忙吗?
谢谢 :)
编辑当我直接在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'"
我得到: 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'"
我得到: http : //tinypic.com/r/5bbac9/8
运行这个:
powershell -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -exec bypass -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"
打开Exchangepipe理shell的罚款: http : //tinypic.com/r/2dglulf/8
首先,让我告诉你如何从一个任务运行脚本:
Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Add arguments (optional): -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; &'Z:\Exchange Powershell\MailboxesApproachingOverQuota.ps1'"
另请注意,您用来运行脚本的用户标识可能需要在本地服务器上被授予权限。
更新:删除-noexit
我猜这个脚本没有签名。 您是否使用Set-ExecutionPolicy -ExecutionPolicy Unrestricted cmdlet启用了未签名脚本Set-ExecutionPolicy -ExecutionPolicy Unrestricted ?
我遇到了同样的问题,发现最简单的方法就是通过bat文件调用命令。 我可以从命令行运行整个命令,但是如果我尝试使用计划任务,无论我做了什么,都不会起作用。
单行batch file修复它。
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 2.0 -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\psscripts\accessrights.ps1"
我在我的PS脚本中设置了脚本,这样我就可以看到它是否完成以及它运行的是什么命令。 我还运行了get-mailboxparmission -identity用户名:\日历以确认更改已反映出来。
干杯
皮特
简单的脚本文件通过任务调度程序工作。 当我使用-Sendmail:$true参数,那么这是工作。 我做了一个.bat文件,并运行该文件,而不是在任务计划程序中的Powershell脚本。 这个.bat文件在我的Exchange 2016上工作。
PowerShell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; . C:\Script\Get-ExchangeEnvironmentReport.ps1 -HTMLReport C:\Script\Get-exchangeReport.html -SendMail:$true -MailFrom:[email protected] -MailTo:[email protected] -MailServer:mail.domain.com"