Primalscript 2021, version 8.0.157
Operating system:
windows 10 enterprise
Trying to connect to ExchangeOnline - using primalscript but giving me an error. Normally when I go to start working on things I run log script, first thing ran, then run a connection script. Connection script connects me to pretty much all the things I will need or should need. Inside there is another script(line8) that I use to connect me to exchange within Primalscript. It does not seem to work and even using Connect-exchangeonline does not work either. It did work a little bit a go. Time frame, I am not completely sure month or two ago it worked.
Also, I have windows terminal installed with powershell,cmd,linux,azure cloud shell and ubuntu.
When I used 'connect-exchangeonline' in PS in windows terminal, it connects without issue. Pops open web window and works.
Account is MFA enforced.
Error - when trying to just use connect-exchangeonline - inside primalscript
Connection script used;PS C:\> Connect-ExchangeOnline
Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].
At E:\OneDrive - PS\Documents\WindowsPowerShell\Modules\ExchangeOnlineManagement\1.0.1\ExchangeOnlineManagement.psm1:277 char:9
+ [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Excha...angeEnvironment:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
- Connect-MsolService
- Start-Sleep -Seconds 5
- Connect-AzureAD
- Start-Sleep -Seconds 5
- Connect-SPOService -Url https://mydomain-admin.sharepoint.com
- Connect-MicrosoftTeams
- Connect-AzureAD
- E:\scripts\Office365\EXonlineConnection.ps1
- cd C:\
- cls
- Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0") `
- -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName`
- |?{$_ -notmatch "_none_"} | select -First 1)
- $EXOSession = New-ExoPSSession
- Import-PSSession $EXOSession
- connect-exchangeonline –delegatedorganization mydomain.onmicrosoft.com
- Connect-ExchangeOnline -ConnectionUri "https://outlook.office365.com/powershell-liveid?SerializationLevel=Full"
Check the locations mentioned in error - the files/folders are there, system is set to keep these files/folders on the local pc. Also checked the application reference for Micro exchange online PS module listed in location and it works.PS C:\> E:\scripts\Office365\EXonlineConnection.ps1
New-ExoPSSession :
At E:\scripts\Office365\EXonlineConnection.ps1:5 char:15
+ $EXOSession = New-ExoPSSession
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], RuntimeException
+ FullyQualifiedErrorId : RuntimeException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
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 E:\scripts\Office365\EXonlineConnection.ps1:7 char:18
+ Import-PSSession $EXOSession
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].
At E:\OneDrive - PS\Documents\WindowsPowerShell\Modules\ExchangeOnlineManagement\1.0.1\ExchangeOnlineManagement.psm1:277 char:9
+ [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Excha...angeEnvironment:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].
At E:\OneDrive - PS\Documents\WindowsPowerShell\Modules\ExchangeOnlineManagement\1.0.1\ExchangeOnlineManagement.psm1:277 char:9
+ [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Excha...angeEnvironment:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
I am not sure what else to try or do at this point. I checked to make sure all the modules are updated (module mgr) and windows updates. I don't want to use windows terminal powershell to run the scripts and test when building them in another program that should be able to connect and function.
Sorry it little scattered train of thought.
sorry almost forgot -
- PS C:\> $PSVersionTable
- Name Value
- ---- -----
- PSVersion 5.1.19041.1237
- PSEdition Desktop
- PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
- BuildVersion 10.0.19041.1237
- CLRVersion 4.0.30319.42000
- WSManStackVersion 3.0
- PSRemotingProtocolVersion 2.3
- SerializationVersion 1.1.0.1