none
Exchange 2010 task scheduled scripts not working if not logged on

    Question

  • Hi All,

    I have done a script for Exchange 2010 and I would like to create a scheduled task for it.

    I have followed the guidance of Mike Pfeiffer's blog.


    http://www.mikepfeiffer.net/2010/02/creating-scheduled-tasks-for-exchange-2010-powershell-scripts/


    However when I set the task as  “Run whether user is logged on or not”, it only works if the user running the task is the administrator. The task is run with high privileges.


    If I do it with a service account (local admin, exchange org admin) it works only when:

    -You run the script for an interactive session of the user or a runas cmd
    -You set the Task as “Run only when the user is logged on” (and the user is logged on)

    If I run the Task as “Run whether user is logged on or not” and the user is not logged on, I get an error on the connection command "Connect-ExchangeServer -auto" (and the task hangs waiting for an answer). The transcript is as follows:

     

    Transcript started, output file is C:\scripts\informes\pruebasconexion.Log.txt

             Welcome to the Exchange Management Shell!

    Full list of cmdlets: Get-Command
    Only Exchange cmdlets: Get-ExCommand
    Cmdlets that match a specific string: Help *<string>*
    Get general help: Help
    Get help for a cmdlet: Help <cmdlet name> or <cmdlet name> -?
    Show quick reference guide: QuickRef
    Exchange team blog: Get-ExBlog
    Show full output for a command: <command> | Format-List

    Tip of the day #31:

    Tab completion reduces the number of keystrokes required to complete a cmdlet. Just press the TAB key to complete the cmdlet you are typing. Tab completion kicks in whenever there is a hyphen (-) in the input. For example:

     Get-Send<tab>

    should complete to Get-SendConnector. You can even use wildcards, such as:

     Get-U*P*<tab>

    Pressing the TAB key when you enter this command cycles through all cmdlets that match the expression, such as the Unified Messaging Mailbox policy cmdlets.


    WARNING: The service  () isn't running. Connecting to remote Powershell requires this service to be running.
    VERBOSE: Connecting to CAS01.XXX.es
     An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://cas01.XX...Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

     

    VERBOSE: Connecting to CAS02.XXX.es
    An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://cas02.XX..Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
     
    WARNING: The service  () isn't running. Connecting to remote Powershell requires this service to be running.

    VERBOSE: Connecting to MBX02.XXX.es
    An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://mbx02.XX...Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
     

    VERBOSE: Connecting to CAS01.XXX.es
    An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://cas01.XX...Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
     

    VERBOSE: Connecting to CAS02.XXX.es
    An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://cas02.XX...Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
     
    WARNING: The service  () isn't running. Connecting to remote Powershell requires this service to be running.
    VERBOSE: Connecting to MBX02.XXX.es
    An internal error occurred. 
        + CategoryInfo          : InvalidArgument: (http://mbx02.XX...Ver=14.1.218.15:Uri) [], PSInvalidOperationException
        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
     


    Failed to connect to an Exchange server in the current site.
    Enter the server FQDN where you want to connect.:


    The error message refers to a unkown "() service", but I have no clue of which service can be needed and it is working only when session is opened.

     The command I run is

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'c:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1';c:\scripts\informes\estado_db_dag.ps1"


    UNICAN-SdeI
    Thursday, August 18, 2011 11:21 AM

Answers

  • Update:

    The problema had to do with the service user. I deleted the service user's profile on the server and the task without a user session began to work.

    No other change, no permissions problem, task properties, no services missed, ..nothing ..just a "bad" profile (although the profile was working).

     


    UNICAN-SdeI
    • Marked as answer by UNICAN-SdeI Friday, August 19, 2011 7:29 AM
    Friday, August 19, 2011 7:29 AM

All replies

  • Update:

    The problema had to do with the service user. I deleted the service user's profile on the server and the task without a user session began to work.

    No other change, no permissions problem, task properties, no services missed, ..nothing ..just a "bad" profile (although the profile was working).

     


    UNICAN-SdeI
    • Marked as answer by UNICAN-SdeI Friday, August 19, 2011 7:29 AM
    Friday, August 19, 2011 7:29 AM
  • I experienced a similar symptom where the scheduled task was getting stuck in the "Running" state. I searched the web for others who have experienced this issue with scheduled tasks, and what I found is that there could be a few reasons why this might happen. 

    I resolved my problem by adding -NonInteractive switch before the -command parameter.

    Hope it helps...

    

    Wednesday, May 09, 2012 3:18 PM
  • I experienced a similar symptom where the scheduled task was getting stuck in the "Running" state. I searched the web for others who have experienced this issue with scheduled tasks, and what I found is that there could be a few reasons why this might happen. 

    I resolved my problem by adding -NonInteractive switch before the -command parameter.

    Hope it helps...

    

    In my case, -NonInteractive does indeed stop the task from getting stuck in a perpetual Running state (until it times out based on the settings in scheduled task), but I was able to deduce why by using Start-Transcript and Stop-Transcript.

    Basically, the connection to Exchange is failing some reason and it sits at a prompt waiting for you to enter a FQDN for an Exchange server (same problem as the OP).  Adding -NonInteractive to the scheduled task does indeed prevent the task from getting stuck waiting for someone to enter a FQDN at a prompt that they cannot interact with, the script still does not execute correctly.  Essentially, adding the "-NonInteractive" switch does not fix the underlying problem of the Exchange connection failing.

    As far as I am able to tell, this has something do with a WinRM problem.  I'm having the same problem as the OP and am trying to troubleshoot it.  In my case, deleting the user profile for the service account does not fix the problem.

    Friday, February 13, 2015 3:02 PM