I'm receiving this error when attempting to connect to Exchange online when using a service account from my automation account. I think the problem may also be that my $credential variable is not passing into my $session variable, but I can't think of any reason why that would be happening.
Error :
New-PSSession : [outlook.office365.com] 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 line:5 char:12
- $session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
- FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again. At line:6 char:42
- Import-Module (Import-PSSession -Session $session -DisableNameCheckin ...
-
~~~~~~~~
Script :
Param ( [string] $Employee = "" ) $credential = Get-AutomationPSCredential -Name '[email protected]' $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://outlook.office365.com/powershell-liveid/' -Credential $credential -Authentication Basic -AllowRedirection Import-Module (Import-PSSession -Session $session -DisableNameChecking -AllowClobber) -Global $mailbox = Get-Mailbox -Identity $Employee Write-Output $mailbox
Help will be highly appreciated