About Session TimeOutSession TimeOut

tarou chabi 731 Reputation points
2022-03-01T03:38:44.437+00:00

Because I'm doing a time consuming process and exporting to csv with powershell, Session disconnected.
I'm going to set a timeout.

$option = New-PssessionOption -IdleTimeout 43200000
Connect-ExchangeOnline -pssessoinoption $option

Please teach me.

  1. Is the only valid way to set IdleTimeout?
  2. Can ”Connect-Msolservice”,”Connect-AzureAD” be set? Will Only Access Token be used??????
    Is it possible to continue the connection even if there is no response between the PC and Azure AD?
    Are Refresh tokens used?
Microsoft 365 Publishing
Microsoft 365 Publishing
Microsoft 365: Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line. Publishing: The process of preparing, producing, and releasing content for distribution or sale.
595 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,351 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 33,706 Reputation points Microsoft Employee
    2022-03-04T21:01:06.837+00:00
    1. You can do it the way you described using the PSSessionOption parameter.

    Another option is to modify the timeout globally for all sessions (and then change it if needed when you're done):

    Set-Item -path WSMan:\localhost\Shell\IdleTimeout -Value ''

    From the documentation:

    > The session uses the idle time-out that is set in the session options, if any. If none is set (-1), the session uses the value of the IdleTimeoutMs property of the session configuration or the WSMan shell time-out value (WSMan:<ComputerName>\Shell\IdleTimeout), whichever is shortest. > > If the idle timeout set in the session options exceeds the value of the MaxIdleTimeoutMs property of the session configuration, the command to create a session fails. > > The IdleTimeoutMs value of the default Microsoft.PowerShell session configuration is 7200000 milliseconds (2 hours). Its MaxIdleTimeoutMs value is 2147483647 milliseconds (>24 days). The default value of the WSMan shell idle time-out (WSMan:<ComputerName>\Shell\IdleTimeout) is 7200000 milliseconds (2 hours). > > The idle time-out value of a session can also be changed when disconnecting from a session or reconnecting to a session. For more information, see Disconnect-PSSession and Connect-PSSession. > > In Windows PowerShell 2.0, the default value of the IdleTimeout parameter is 240000 (4 minutes).

    2) a) What do you mean by "set"? If you're asking whether you can sign in automatically with the current user credentials, this is not supported. However, it is possible to use Connect-AzureAD with stored credentials, and you can set the parameters connecting to those services.

    You can connect using the access token:

    Connect-AzureAD -TenantId "$tenantId"  -AadAccessToken $tokenResponse.access_token -AccountId "$appId"
    

    (See related thread.)