How to Create AD User in Specific OU using Microsoft AD Spoke.

Sravani36
Tera Expert

Hi I'm creating the users in AD  but i want to add the users in a specific OU for that i have added the powershell script as below which I have referred from community. but to create the input for OU the create user action was not editable, will it fine if we create a custom action for it or we can edit the oob?

Sravani36_0-1665719180601.png

 

Sravani36_1-1665719204824.png

 

5 REPLIES 5

Callum69
Tera Contributor

I faced similar kind of issue last time, I am still searching for some proper solution.
Fragomen Connect

Niklas Peterson
Mega Sage
Mega Sage

Hi @Sravani36 ,

Can't you use the "Update AD Object OU" action after "Create User" action to put the user in the desired OU?

 

Regards,
Niklas

Hi @Niklas Peterson,

 

Yeah, I have added it and also to customize the create user action for adding the other input as well like  samaccountName,  I have edited the powershell script for adding this SamAccountName and created the input in the flow but still the changes are not reflecting, the samaccount name is populating with the Sravani ch. Any idea how to fix this?

 

PowerShell script:

 

import-module activedirectory;

$SamAccountName = $SamAccountName -replace "%27","'";
$UserPrincipalName = $UserPrincipalName -replace "%27","'";
$DisplayName = $DisplayName -replace "%27","'";
$GivenName = $GivenName -replace "%27","'";
$Surname = $Surname -replace "%27","'";
$EmailAddress = $EmailAddress -replace "%27","'";
$MobilePhone = $MobilePhone -replace "%27","'";
$Title = $Title -replace "%27","'";
$Department = $Department -replace "%27","'";
$StreetAddress = $StreetAddress -replace "%27","'";
$City = $City -replace "%27","'";
$State = $State -replace "%27","'";
$Country = $Country -replace "%27","'";
$Password = $Password -replace "%27","'";
if($Password){
$pwrd = $Password | ConvertTo-SecureString -AsPlainText -Force
}

if ($UserPrincipalName.length -gt 20) {
Write-Host "Input length exceeded";
exit;
};

if($pwrd){
$enabled = $True;
New-ADUser -Name $DisplayName -AccountPassword $pwrd -DisplayName $DisplayName `
-GivenName $GivenName -SamAccountName $SamAccountName -Surname $Surname `
-EmailAddress $EmailAddress -UserPrincipalName $UserPrincipalName `
-MobilePhone $MobilePhone -Title $Title -Department $Department `
-Enabled $enabled -StreetAddress $StreetAddress -City $City `
-State $State -Country $Country -Credential $cred -Server $computer -PassThru;
}
else {
New-ADUser -Name $DisplayName -DisplayName $DisplayName -GivenName $GivenName`
-SamAccountName $SamAccountName -Surname $Surname -EmailAddress $EmailAddress`
-UserPrincipalName $UserPrincipalName -MobilePhone $MobilePhone -Title $Title`
-Department $Department -StreetAddress $StreetAddress -City $City`
-State $State -Country $Country -Credential $cred -Server $computer -PassThru;
}

 

sAMAccountName A-XXX(windows logon Name to update as this)
userPrincipalName A-xxx@gmail.com
displayName - Sravani ch

 

Hi,

Sorry no. My suggestion was more to combine "Create User" and "Update AD Object OU" actions in the Flow to not have to do any powershell scripting. 

 

Regards,

Niklas