Cannot make Exchange PowerShell work as Scheduled Task, why??

This topic contains 9 replies, has 5 voices, and was last updated by Profile photo of Max Kozlov Max Kozlov 1 month, 2 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #49323
    Profile photo of tommls
    tommls
    Participant

    I've tried a zillion things in the Actions panel and I still get an opcode of 2, supposedly meaning the file can't be found...AND no events ever get written into the log like they are supposed to be. This is for a scheduled task running ON the Exchange 2010 server.

    The parameters line is:

    -version 2.0 -NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\scripts\Troubleshoot-DatabaseSpace.ps1 -Server e10 -PercentEdbFreeSpaceThreshold 10 -PercentLogFreeSpaceThreshold 10"

    I get the same result if I point to this file in the Exchange scripts folder, I copied it from there into C:\scripts.

    The action to run is:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    The Start In is:

    C:\Windows\System32\WindowsPowerShell\v1.0\

    What is wrong with my setup, please????????

    Scripts permission is RemoteSigned, the script works with all these parameters etc. if I manually run it from a batch file.
    I've double-checked the presence of each file involved.
    This is an Exchange 2010 on Windows Server 2008 R2, all current patches.

    Thank you, Tom

    #49632
    Profile photo of Don Jones
    Don Jones
    Keymaster

    What identity is running the task?

    #49644
    Profile photo of tommls
    tommls
    Participant

    It's being run with the Administrator login (domain admin account, highest privileges, run logged in or not).
    The task runs but it doesn't do what it's supposed to do, put things into the event log.
    Thank you, Tom

    #49652
    Profile photo of Don Jones
    Don Jones
    Keymaster

    That being the case, it's honestly hard to say without being able to sit in front of it and explore. Have you tried running a very simple script, that perhaps doesn't use Exchange at all, just to see if you can get ANYTHING to run as a Task?

    #49658
    Profile photo of tommls
    tommls
    Participant

    I'll try using another simple Exchange script...
    I had similar problems with a login monitoring script...and gave up.
    But now I really need to figure out doing something like this. 🙂
    Thank you, Tom

    #50144
    Profile photo of Nick Jaggers
    Nick Jaggers
    Participant

    Does the host where the script resides have the same EMS as the Exchange servers? Some commands won't run even if you include a 'load snapin' command : Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010
    Been caught out with this before!

    #50146
    Profile photo of tommls
    tommls
    Participant

    The scheduled task IS running ON the Exchange 2010 server. As administrator.
    I have not had opportunity to work on this b/c of putting out fires...
    Thank you, Tom

    #50152
    Profile photo of ertuu85
    ertuu85
    Participant

    I had similar problems....

    Running this from my exchange server's Task Scheduler works great:

    Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Add arguments: -command ". 'D:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\scripts\sep_attack.ps1"

    Have you tried removing ' -Server e10 -PercentEdbFreeSpaceThreshold 10 -PercentLogFreeSpaceThreshold 10' and seeing if it works? Maybe just add a read-host at the end of your script to see what its doing?

    #50156
    Profile photo of tommls
    tommls
    Participant

    One is required to put the -server parameter so the script knows which server to work on.
    I think I tried removing the other params.
    It will be a couple weeks before I can get back to this.
    Thank you, Tom

    #50428
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    Are you tried to run your command from cmd and not task scheduler?
    Fine if cmd will be executed from the same user as in task scheduler

    runas /user:domain\requireuser cmd
    >powershell -command ........

    and when you see that it executed exactly as you need and produce output you need, just copy/paste latest command to scheduler

    • This reply was modified 1 month, 2 weeks ago by Profile photo of Max Kozlov Max Kozlov.
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.