MID Server/Powershell Script Error

Aniket Bhanse
Tera Guru

I have created a new Action in the flow designer which will create a user account in a domain in Microsoft AD.

However I am getting the below error when I execute the Action in Flow Designer: find_real_file.png

 

As I look at the error closely, it seems the Powershell script is giving the error. I am not sure what is wrong with the script as it looks good to me.

import-module activedirectory;

 $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","'";
 $PhysicalDeliveryOfficeName =   $PhysicalDeliveryOfficeName -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 $UserPrincipalName -AccountPassword $pwrd  -DisplayName $DisplayName `
          -GivenName $GivenName -SamAccountName $UserPrincipalName -Surname $Surname   `
          -EmailAddress $EmailAddress  -UserPrincipalName $UserPrincipalName `
          -MobilePhone $MobilePhone -Title $Title -Department $Department `
          -Enabled $enabled -StreetAddress $StreetAddress -City $City `
          -State $State -Country $Country -physicalDeliveryOfficeName $PhysicalDeliveryOfficeName `
          -Credential $cred -Server $computer -PassThru;
}
else {
    New-ADUser -Name $UserPrincipalName -DisplayName $DisplayName -GivenName $GivenName`
           -SamAccountName $UserPrincipalName -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;
}

Can anyone suggest where I may be getting wrong.

1 REPLY 1

Vasantharajan N
Giga Sage
Giga Sage

Please check whether you are able to manually run the Powershell script from the Mid Server.

if you are able to run it then check the Service Account which you use to run the Mid Server Service has the privilege to run the Script using the option "Run As".

in the Powershell script you can add loggers and error handling to get more detailed information about the error. 

 


Thanks & Regards,
Vasanth