Connection to ExchangeOnline

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Connection to ExchangeOnline

Post by Reddrgn2 »

Product, version and build:
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
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
Connection script used;
  1. Connect-MsolService
  2. Start-Sleep -Seconds 5
  3. Connect-AzureAD
  4. Start-Sleep -Seconds 5
  5. Connect-SPOService -Url https://mydomain-admin.sharepoint.com
  6. Connect-MicrosoftTeams
  7. Connect-AzureAD
  8. E:\scripts\Office365\EXonlineConnection.ps1
  9. cd C:\
  10. cls
EXonlineConnection.ps1-
  1. Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0") `
  2. -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName`
  3. |?{$_ -notmatch "_none_"} | select -First 1)
  4.  
  5. $EXOSession = New-ExoPSSession
  6.  
  7. Import-PSSession $EXOSession
  8.  
  9. connect-exchangeonline –delegatedorganization mydomain.onmicrosoft.com
  10. Connect-ExchangeOnline -ConnectionUri "https://outlook.office365.com/powershell-liveid?SerializationLevel=Full"
Error when using Exonlineconnection script inside primalscript-
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
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.

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 -
  1. PS C:\> $PSVersionTable                              
  2.                                                      
  3. Name                           Value                  
  4. ----                           -----                  
  5. PSVersion                      5.1.19041.1237        
  6. PSEdition                      Desktop                
  7. PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
  8. BuildVersion                   10.0.19041.1237        
  9. CLRVersion                     4.0.30319.42000        
  10. WSManStackVersion              3.0                    
  11. PSRemotingProtocolVersion      2.3                    
  12. SerializationVersion           1.1.0.1                
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Connection to ExchangeOnline

Post by Alexander Riedel »

I did a quick check for Connect-ExchangeOnline and it properly prompted for credentials.
The ExchangeOnlineManagement module version I have installed is 2.0.5
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.