Invoke Powershell error - New-ADUSer

Hi All,
I need to create a new user account in Active Directory with PowerShell. I am using below script for that:

Param(
[Parameter(Mandatory=$true)] [string]$userID,
[Parameter(Mandatory=$true)] [string]$name,
[Parameter(Mandatory=$true)] [string]$server,
[Parameter(Mandatory=$true)] [string]$pwd,
[Parameter(Mandatory=$true)] [string]$loc
)

$username = $username; $password = $password; $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force; $mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd);

New-ADUser -Name $name -SamAccountName $userID -path $loc -Accountpassword (Read-Host -AsSecureString $pwd) -Enabled $true -Server $server -Credential $mycreds

This is running fine in powershell, however when I run this in Uipath using invoke powershell activity, It throws below error:
Invoke Power Shell: A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message:

Just to add lil more context, Get-ADUser works perfectly fine.

Has anyone ever experienced this issue? Please pour in your suggestions/recommendations.
Thanks!

Hey @kaurM

When you run it in powershell manually without UiPath, did you get any user prompt ?

Thanks
#nK

Hi,

No I don’t get any prompt in powerShell.

Hello @kaurM

Did you tried with the Active directory activities available in the uipath. It is easy to use and handle.

Okay got it !

As try the one suggested by @Rahul_Unnikrishnan

If nothing helps please let us know.

Hi Rahul,
Thanks for your response!
There are some security constraints regarding the use of Active Directory scope in the bank I work with. We are facing a PasswordNotRequired flag with the account created with ‘Create User’ activity under Active Directory Scope.
So the ask here is to use powershell script to create a new user account.

Thanks for your response!
There are some security constraints regarding the use of Active Directory scope in the bank I work with. We are facing a PasswordNotRequired flag with the account created with ‘Create User’ activity under Active Directory Scope.
So the ask here is to use powershell script to create a new user account.

@kaurM

As per my understanding the below statement is causing the issue here.

Read-Host -AsSecureString $pwd) -Enabled $true

So if you execute this in powershell ISE, is it asking to enter the password?

@kaurM

One alternate solution is you can create a user without password and then add password as below.

Set-ADAccountPassword -Identity ‘CN=Elisa Daugherty,OU=Accounts,DC=Fabrikam,DC=com’ -Reset -NewPassword (ConvertTo-SecureString -AsPlainText “p@ssw0rd” -Force)

Hi Rahul,
In PowerShell, No, its not asking to enter the password.
Also, Creating an account and setting up a password should be one transaction.
If I create an account first and then set the password, that user account gets flagged red as per the bank’s policy which should not happen at all.

@kaurM Give me some time. Let me check for the code. Did similar automation.
We started with Powershell and then moved to UiPath activity.

You are right, this was giving me issue. I removed this line and passed password as secure string variable here.

Thanks so much, I had been struggling with it for last two days.

Thanks!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.