- 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.)