I have a PowerShell script that works when entered directly into the PowerShell. The PowerShell program is run with the 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'"
I have tried about 10 different ways in Windows Task Scheduler to first open the shortcut above and then run my saved script file but it won't work. It hangs on 'Running'.
The script is located here:
Z:\Exchange PowerShell\MailboxesApproachingOverQuota.ps1
Note that script content can be copied and pasted into the PowerShell shortcut above and it runs absolutely fine and emails me the output as it should.
Note that the PowerShell instance I use is from the shortcut shown above which already has arguments in it - hence why I'm stumped what to put where in Task Scheduler.
Any help please?
Thanks :)
EDIT When I use the following directly in 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'"
I get: http://tinypic.com/r/n1fkmg/8
When I use the following:
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'"
I get: http://tinypic.com/r/5bbac9/8
Running this:
powershell -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -exec bypass -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"
Opens the Exchange Management Shell fine: http://tinypic.com/r/2dglulf/8