locked
Invoke-Command RemoteException "Your session has expired, please login again." RRS feed

  • Question

  • I am calling a series of Invoke-Command with script blocks, and keep getting a RemoteException of the following:

    The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Your session has expired, please login again.
    Your session has expired, please login again.

    I have set $ErrorActionPreference = "Stop" to catch errors; however, this also seems to be catching some session time-out problem.

    I tried executing the invoke-commands with the following session switch:

    $PS_Session_Options = New-PSSessionOption
    $PS_Session_Options.IdleTimeout = (New-TimeSpan -Minutes 180)
    $PS_Session = New-PSSession -ComputerName myServer -SessionOption $PS_Session_Options

    such as:

    Invoke-Command -Session $PS_Session -ScriptBlock {program -info}

    While in either a remote powershell session or powershell ISE, I have no problem calling these invoke-commands and "not" getting any session time-out problems.  It's only when the script has been setup via Task Schedular (using appropriate credentials).

    What PSSession Option do I need to configure for this?  I've tried extending IdleTimeout, but doesn't work.  Would CancelTimeout or OpenTimeout set to zero (0) do the trick?

    Sunday, March 29, 2015 3:52 AM

Answers

  • Hi Anna,

    I was able to resolve the issue.  It seems that when issuing the ScriptBlock to execute a program, PowerShell was not handling something as expected. I found that by adding the following to the command line execution:

    Invoke-Command -Session $PS_Session -ScriptBlock {cmd /c 'p.exe -info 2>&1'}

    By wrapping the command line executable and arguments and piping them to stdout, it resolves all those problems.

    found the tip here: http://stackoverflow.com/questions/818255/in-the-shell-what-is-21

    I think I've answered my own question on this one :D

    • Marked as answer by tsw Monday, March 30, 2015 5:06 PM
    Monday, March 30, 2015 5:06 PM

All replies

  • well... I attempted to extend the timeouts indefinitely, but still... just a second or two after the script launches I get the same error as before.

    these are the properties for the Session that I added:

    $PS_Session_Options.CancelTimeout = 0
    $PS_Session_Options.OpenTimeout = 0
    $PS_Session_Options.OperationTimeout = 0

    I'm at a loss on this... no clue what other timeout values could be causing the "Your session has expired, please login again" error...  I'll try setting $ErrorActionPreference to "continue" tonight and see what happens, but that just seems to defeat the entire purpose of even using a try/catch/finally block.

    Sunday, March 29, 2015 3:50 PM
  • just for reference, here is the entire PS>TerminatingError() message:

    PS>TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Your session has expired, please login again."
    >> TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Your session has expired, please login again."
    The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Your session has expired, please login again.
    Your session has expired, please login again.
    At C:\BackupScripts\myRemoteBackup.ps1:38 char:1
    + $output = Invoke-Command -Session $PS_Session -ScriptBlock {program -verify}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Your session ha...se login again.:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
        + PSComputerName        : myRemoteServer

    Sunday, March 29, 2015 3:54 PM
  • Hi Tsw,

    To troubleshoot this issue, please change the value of the variable "$ErrorActionPreference" back to "Continue", and add the cmdlet "start-transcript -path c:\transcripts\transcript0.txt" at the beggining of the .ps1 file, which will record the script history and the error information, and add the "Stop-Transcript" cmdlet in the end.

    Please also make sure the account used to run the scheduled task is the user account you manually launch the script in Powershell console.

    If there is anything else regarding this issue, please feel free to post back.

    If you have any feedback on our support, please click here.

    Best Regards,

    Anna Wang

    TechNet Community Support


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Monday, March 30, 2015 11:30 AM
  • Hi Anna,

    I was able to resolve the issue.  It seems that when issuing the ScriptBlock to execute a program, PowerShell was not handling something as expected. I found that by adding the following to the command line execution:

    Invoke-Command -Session $PS_Session -ScriptBlock {cmd /c 'p.exe -info 2>&1'}

    By wrapping the command line executable and arguments and piping them to stdout, it resolves all those problems.

    found the tip here: http://stackoverflow.com/questions/818255/in-the-shell-what-is-21

    I think I've answered my own question on this one :D

    • Marked as answer by tsw Monday, March 30, 2015 5:06 PM
    Monday, March 30, 2015 5:06 PM
  • Hi Tsw,

    Glad to hear that =)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Tuesday, March 31, 2015 1:07 AM
  • [edit]

    never mind...  the "Enter-PSSession" did not resolve it either...

    so, still having an issue with this. not sure why.



    • Edited by tsw Friday, April 17, 2015 6:13 PM
    Friday, April 17, 2015 6:06 PM
  • well... hopefully I can put this to rest now...

    had nothing to do with PowerShell... all of that seemed to be working correctly.  It had to do with the Perforce server I was issuing commands to remotely and the LDAP ticket expiration.  I have a workaround which I'm currently testing, and if this finally solves the problem, I'll be writing a blog article about it to share with others.

    Sunday, April 19, 2015 4:58 PM