Hybrid Exchange/O365 Automation (Off boarding)

Occasional Visitor

I have been working with a script that was handed off to me. Its purpose was to automate some of our off-boarding processes on our Hybrid Exchange/Microsoft O365 server. It's worked in the past, but has been slowly breaking as time has moved on.

Currently, my biggest challenge is trying to figure out why it won't let myself and a few other admins connect to our exchange/O365 server. I have a sneaking suspicion it's related to the currently installed modules/available cmdlets.  The following modules are what is currently installed on my work machine;

Version       Name                           Repository       Description
-------           ----                              ----------           -----------
2.0.2.135   AzureAD                         PSGallery            Azure Active Directory V2 General Availability Module....

2.0.5 ExchangeOnlineManagement PSGallery           This is a General Availability (GA) release of Exchange Online PowerShell V2 module....

1.1.183.57 MSOnline                       PSGallery             Microsoft Azure Active Directory Module for Windows PowerShell

1.4.7 PackageManagement            PSGallery              PackageManagement (a.k.a. OneGet) is a new way to discover and install software packages from around the web....

2.2.5 PowerShellGet                        PSGallery              PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Mod...

------------------------------------
I'm currently using;

$Credentials = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
-------------------------------------
Which presents this error:
New-ExoPSSession : unknown_user_type: Unknown User Type
At C:\users\jbarckley\AppData\Local\Apps\2.0\RRGW2CXO.DNX\4YNQ6P50.D87\micr..tion_1f16bd4ec4c2bb19_0010.0000_673f37c317fb5976\CreateExoPSSession.ps1:302 char:30
+ ... PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName.Va ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AdalException
+ FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession

-----------------------------------------------------------------------------------------------------
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : For more information, see the about_Remote_Troubleshooting Help topic.
At line:2 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108477,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:3 char:18
+ Import-PSSession $Session
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
----------------------------------------------------------------

Do these cmdlets only work in the EXO v1 Module?

Any advice would be great!


 

1 Reply
Since you have the ExchangeOnlineManagement module installed, just use the Connect-ExchangeOnline cmdlet instead.