Hi
I thought that using native Azure powershell would be easier and cleaner to look at so I wrote the following
Import-Module Adaxes
$userDomain = "domain.com"
$memberDomain ="%member%".Split(",")[-3]
if ($memberDomain -match "DC=") { $userDomain = $memberDomain.Split("=")[1] + "." + $userDomain }
$userUPN = (Get-AdmUser -Identity "%member%" -Server $userDomain -AdaxesService localhost -Properties UserPrincipalName).UserPrincipalName
$Context.LogMessage("$userUPN", "Information")
#Get Credentials and connect to AzureAD
$cred = $Context.GetOffice365Credential()
Import-Module AzureAD
Connect-AzureAD -Credential $cred
$myVar = Get-AzureADTenantDetail
$Context.LogMessage("$($myVar.DisplayName)", "Information")
$userId = (Get-AzureADUser -SearchString $userUPN).ObjectId
$Context.LogMessage("$userId", "Information")
Get-AzureADUser -SearchString $userUPN | Get-AzureADUserMembership | ForEach-Object {
$Context.LogMessage("$($_.DisplayName)", "Information")
if ($_.DisplayName -match "Group naming convention") {
$Context.LogMessage("Remove $($_.DisplayName)", "Information")
Remove-AzureADGroupMember -ObjectId $_.objectid -MemberId $userId
}
}
Disconnect-AzureAD
However, for some reason the users Azure ObjectId never seems to be returned.
I'm running this in a business rule which acts before adding a user to the group, but the users UPN is returned.
We are quite far behind with the AzureAD module, but the same commands work fine in native powershell.
Also, the Get-AzureADTenantDetail command works fine, so I know that I'm connected to AzureAD.