Avatar of ichibanto
ichibanto
 asked on

New-QADuser error SAPIEN

I'm running the code below with SAPIEN.  It runs OK in Powershell alone.  But in SAPIEN I get the following error below.  I have full admin privilages.  I've tried specifying a different container for the new user.

MY ERROR

ERROR:     + CategoryInfo          : NotSpecified: (:) [New-QADUser], DirectoryServicesCOMException
ERROR:     + FullyQualifiedErrorId : System.DirectoryServices.DirectoryServicesCOMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewUserCmdlet
ERROR:

MY SCRIPT IN SAPIEN

$OnLoadFormEvent={
#TODO: Initialize Form Controls here
if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Quest.ActiveRoles.ADManagement
}
}


$SAMACCOUNTNAME_TextChanged={
      #TODO: Place custom script here
      WRITE-OUTPUT "$SAMACCOUNTNAME"
      
}

$Firstname_TextChanged={
      #TODO: Place custom script here
      WRITE-OUTPUT "$FIRSTNAME"
}

$Surname_TextChanged={
      #TODO: Place custom script here
      WRITE-OUTPUT "$SURNAME"
}





$buttonCreateAccount_Click={
      #TODO: Place custom script here
      New-QADUser -ParentContainer "DOMAIN/Department/container" -Name "$FIRSTNAME $SURNAME" -SamAccountName "$SAMACCOUNTNAME" -DisplayName "$FIRSTNAME $SURNAME" -FirstName "$FIRSTNAME" -LastName "$SURNAME" -UserPassword "PassW0rd234"
}
Powershell

Avatar of undefined
Last Comment
ichibanto

8/22/2022 - Mon
Dale Harris

I would create a separate function called "Create-NewUser" and store any textfields to variables, and try again.

Function Create-NewUser {

$FirstName = $FirstName_text.text
$SurName = $Surname_text.text
$SAMAccountName = $SAMAccountName_Text.text

New-QADUser -ParentContainer "DOMAIN/Department/container" `
-Name "$FIRSTNAME $SURNAME" `
-SamAccountName "$SAMACCOUNTNAME" `
-DisplayName "$FIRSTNAME $SURNAME" `
-FirstName "$FIRSTNAME" `
-LastName "$SURNAME" `
-UserPassword "PassW0rd234"

}#end function

$buttonCreateAccount_Click={
      #TODO: Place custom script here
      Create-NewUser
}#end function

Open in new window


I would stay away from only allowing button_click events to hold your information to create accounts, which is why I recommend the separate function.  We could make it work within that _click event, but if you ever wanted anything else to initiate a new account (Drop down menu, mouse-over of a certain area, etc), you wouldn't be able to call the _click event.

Lastly, I would recommend using the .Net way to name your fields.

$txtFirst is a textbox (txt) that holds information about the first name
$lblFirst is the label that goes right above the textbox to tell the user what to put in there
$drpFirst is a dropdown for first name
$lstFirst is a listbox

Every object in .Net has a different type of way to grab the information presented.  You definitely need to keep track of the properties on the right side of your Powershell Studio window to see how to grab information.

One last thing, if you do any variable manipulation (Create Display Name from $txtFirst and $txtLast), it will only be available in that function.  In order to make it globally available, you must give it the $global: assignment, like this: $global:txtFirst

HTH,

DH
ichibanto

ASKER
Hi I will try this tomorrow thank you so much you're great. Sapien is a mine field.  Cheers.
ichibanto

ASKER
I still get this error.  I've changed the code to the above snippet creating a new function.

MainForm.pff (18): ERROR: At Line: 18 char: 12
ERROR: +     New-QADUser <<<<  -ParentContainer "domain/OU/OU2/abc" `
ERROR:     + CategoryInfo          : NotSpecified: (:) [New-QADUser], COMException
ERROR:     + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.NewUserCmdlet
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Dale Harris

Have you tried the new-qaduser command with the same -parentcontainer information?  It looks like it doesn't like New-QADUser though.  I would test in command line.
ichibanto

ASKER
I've tried it with different container information. I think I'm going to establish the command works alone first before retrying. The new function works great just shame about the container. Will report back Monday.
Neil Russell

Try using....

 -ParentContainer "ou=abc,ou=ou2,ou=ou1,dc=domain,dc=com"  

instead
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ichibanto

ASKER
I've requested that this question be deleted for the following reason:

No longer required
Dale Harris

I'm not sure a cancel request makes sense on this one.  If you decided to go a different way with the script, will you let us know?  If you were able to figure out the issue, will you let us know the solution?  We provided some pretty solid troubleshooting steps, so I'm not sure what happened.
ichibanto

ASKER
The solution I used was windows .net classes to provide a menu interface following the licence expiring on the sapien product.  The .net method was provided by MS "scripting guy" plus other widely available sources. Thank you for everybody's assistance on this one.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
ichibanto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ichibanto

ASKER
This the easiest method for providing a menu without getting bogged down with dev software.