EnricoGiacomin It works quite smooth with other Office 365 services.
This example shows how to authenticate/connect to MSOnline in one session and use that session from another session:
# Session 1 (establish new MSOnline session):
$session = New-PSSession -ComputerName . -SessionOption (New-PSSessionOption -IdleTimeout 900000)
$guid = $session.InstanceId
[GUID]::Parse($guid)
# Output = a02b4ae5-65f1-4fad-a139-73eb211be80f
Invoke-Command -Session $session -ScriptBlock {$cred = Get-Credential}
Invoke-Command -Session $session -ScriptBlock {Connect-MsolService -Credential $cred}
Disconnect-PSSession $session
Then use the already established MSOnline session from another PowerShell session:
# Session 2: (connect using the session GUID from before)
$session = Get-PSSession -ComputerName localhost -InstanceId ([GUID]"a02b4ae5-65f1-4fad-a139-73eb211be80f")
Connect-PSSession $session
Invoke-Command -Session $session -ScriptBlock {Get-MsolUser -UserPrincipalName jens.m.knudsen@easy365manager.onmicrosoft.com | ft}
# Output:
#UserPrincipalName DisplayName isLicensed
#----------------- ----------- ----------
#jens.m.knudsen@easy365manager.onmicrosoft.com Jens M. Knudsen True
I guess you can probably translate this to an application/certificate authenticated scenario? I haven't worked on that.
/ Morten
Easy Office 365 administration: https://easy365manager.com/