0 votes

Maybe there is a better way to accomplish this, so I'm open to suggestion.

We are in a hybrid setup between onprem and M365. When we create a new user, they are automatically added to a Security Group in our onprem AD. Membership in that group then gets synced to a Mail Enabled Security Group in Exchange Online. We rely on a scheduled PowerShell script to sync the group membership.

The script is helpful because does both these functions:

  • If a user is added to the onprem group, they are added to the cloud group
  • If a user is removed from the onprem group, they are removed from the cloud group

The PowerShell script stopped working due to a cmdlet being depreciated - "CreateExchangeOnlinePSSession". So I upgraded our Adaxes to the latest version and, per the Adaxes KB, switched the script to use the "ConnectExchangeOnline" instead.

But now we're getting an error related to the Import-PSSession $session part of the script:

#Connect to Exchange Online
$session = $Context.CloudServices.ConnectExchangeOnline()
Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Get-DistributionGroupMember", "Add-DistributionGroupMember", "Remove-DistributionGroupMember"

The error is:

Cannot validate argument on parameter 'Session'. The argument is null.

Any thoughts on why it might be saying the 'Session' parameter is null? It should be getting populated by the ConnectExchangeOnline command in the previous step, right?

If needed, I can provide the full script.


by (20 points)

1 Answer

0 votes
by (277k points)

Hello Andrew,

Your script update is incorrect as method ConnectExchangeOnline does not return anything and there is no session established any longer. For an example of connecting to Exchange Online in Adaxes scripts, see https://www.adaxes.com/script-repository/connect-to-exchange-with-powershell-s506.htm.

Related questions

0 votes
1 answer

Hi, something has happened to our shared mailbox creation, on prem and syncing with o365 (we're a hybrid environment) the process works. With no issues. When a new shared ... I'm assuming at the moment it's an Adaxes issue with accessing the o365 information.

asked Jan 27, 2023 by gazoco (490 points)
0 votes
1 answer

I've got the following script as part of a larger piece where param-members is an AD Object picker list seperated by a ' ; ' currently: New-DistributionGroup -Name ... or convert that to username but I'm struggling to achieve that with multiple Users selected

asked Jan 27, 2020 by richarddewis (260 points)
0 votes
1 answer

Is it possible to script having users added (or removed) from a Security Group based on another AD Attribute? I have found ways to do this in Powershell (something like): ... just utilize the PS script and just run it through Adaxes on a timed fashion? Thanks!

asked Oct 7, 2014 by PunkinDonuts (360 points)
0 votes
1 answer

Rule-based membership fails for security enabled distribution group with error "The term 'Add-DistributionGroupMember' is not recognized as the name of a cmdlet, function, ... Exchange Online before running this PowerShell command. Here is rule based set up.

asked Mar 7, 2023 by KIT (910 points)
0 votes
1 answer

Hi after the user acount is created in Active Directory I need the business rule to pause for 30mins for the azure sync to take place before the rule can continue to add the 365 license.

asked May 24 by johanpr (120 points)
3,411 questions
3,108 answers
545,830 users