The script demonstrates how to connect to Exchange from Adaxes with the help of PowerShell.
Exchange Online
PowerShell
try
{
# Get the object ID in Microsoft 365
$objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
return # The user doesn't have a Microsoft 365 account
}
# Connect to Exchange Online
$Context.CloudServices.ConnectExchangeOnline()
# Change mailbox type
Set-Mailbox $objectId.ToString() -Type Shared
# TODO: replace with the code you need to execute
Exchange On-Premises
Parameter:
- $exchangeServer - Specifies the Fully Qualified Domain Name (FQDN) of your Exchange server.
PowerShell
$exchangeServer = "exchangeServer.domain.com" # TODO: modify me
try
{
# Connect to Exchange server
$session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
Import-PSSession -session $session -CommandName "Set-Mailbox"
# Change mailbox type
Set-Mailbox "%distinguishedName%" -Type Shared
# TODO: replace with the code you need to execute
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession -Session $session}
}
I see no errors thrown and when i check the TestGroup in O365 the user is not added.
Hello Anas,
You can use the below script to add the target user to the group whose name is specified in the $groupName variable.
If you need to automate membership in Office 365 groups, have a look at the following scripts from our repository: https://www.adaxes.com/script-repository/add-user-to-office-365-distribution-groups-based-on-business-unit-membership-s254.htm.
There is no need to use any scripts. It can be done using the built-in Modify Exchange properties action in a scheduled task. The task will include the If has Exchange mailbox condition.
If some of the mailboxes are not in Exchange Online and should not be affected by the task, use the following script from our repository in the task condition:https://www.adaxes.com/script-repository/check-whether-user-has-mailbox-in-exchange-online-s303.htm.