Again, I have to wonder about the error message. I have an established powershell session both before and after I enter the command that says I cannot connect:
PS C:\script> get-pssession
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
12 ExchangeOnli... outlook.offi... RemoteMachine Opened Microsoft.Exchange Available
PS C:\script> .\sync-modernmailpublicfolders.ps1 -credential(Get-Credential) -CSVSummaryfile:c:\script\20211001-PFSync.c
sv
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove File" on target "C:\script\20211001-PFSync.csv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a
[10/1/2021 11:24:00 AM] Creating an Exchange Online remote session...
InitializeExchangeOnlineRemoteSession : Unable to create a remote shell session to Exchange Online. The error is as
follows: "Connecting to remote server outlook.office365.com failed with the following error message : Access is
denied. For more information, see the about_Remote_Troubleshooting Help topic.".
At C:\script\Sync-ModernMailPublicFolders.ps1:506 char:5
+ InitializeExchangeOnlineRemoteSession;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,InitializeExchangeOnlineRemoteSession
PS C:\script> get-pssession
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
12 ExchangeOnli... outlook.offi... RemoteMachine Opened Microsoft.Exchange Available
PS C:\script>