Query existing user mail from AD via integration hub AD spoke with multiple domains.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 08:32 AM
My scenerio is-
I have to check/query AD with existing users using mail it could be firstname.lastname, firstname.lastname1, firstname.lstname2......till 10.
Challenge is no OOB Action persent to query for multiple domains and make a loop to iterate till 10 and check for existing user before creating AD user via AD Spoke integration hub.
Anyone please provide solution.
Saba Anjum
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 09:33 PM - edited 09-10-2023 09:34 PM
Hi,
You need to create a custom action for this.
Sample PowerShell for the same is -
Import-Module ActiveDirectory -WarningAction SilentlyContinue
$fname= $fname-replace "%27","'";
$lname= $lname-replace "%27","'";
$mailDomain= $mailDomain-replace "%27","'";
try
{
$upnalias=$fname+"."+$lname;
$num=$null;
$index = 2;
$stopFlag="Run";
do
{
$toBeUPN=$upnalias+$num+$mailDomain;
$existingAccounts = (Get-ADUser -Filter "UserPrincipalName -eq '$toBeUPN'" -Credential $cred -Server $computer | Select-Object -ExpandProperty samAccountName);
if($existingAccounts -eq $null)
{
$result= $toBeUPN
$status = "Success";
$stopFlag="Stop";
}
else
{
[string]$num=$index;
$index++;
}
} until ($stopFlag -eq "Stop")
}
catch
{
$result = "Error";
$status = "Error";
}
$response = @{
status = $status
body = $result
} | convertTo-Json
Write-Output $response
Thanks and Regards,
Saurabh Gupta