Creating new user in AD

Hi all,
I am trying to write a script to create new user in Active Directory using power-shell
$sam = "13653123"
try{
get-aduser -Identity $sam -ErrorAction Stop
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
$error1= [System.Windows.Forms.MessageBox]::Show("ERROR : Account Not found")
$SamAccountName = $sam
$gn = "Jack Sparrow"
$Initials = "ZX"
$dn = "$gn "+" $Initials"
$Department = "1260"
$title = "AM"
$pwd1 = read-host "Please enter the password"
$pwd2 = read-host "Please enter the password"
if($pwd1 -eq $pwd2)
$pwd = $pwd1 = $pwd2
try
$userprinicpalname = $SamAccountName + "@XXX.com"
New-ADUser -SamAccountName $SamAccountName -UserPrincipalName $userprinicpalname -GivenName $gn -Initials $Initials -Name $dn -DisplayName $dn -Title $title -Department $Department -Office $Department -Path "OU=XXXX,DC=XXX,DC=com" -AccountPassword (ConvertTo-SecureString $pwd -AsPlainText -force) -Enabled $True -PasswordNeverExpires $False -ErrorAction Stop
catch [Microsoft.ActiveDirectory.Management.ADPasswordComplexityException]
$error7= [System.Windows.Forms.MessageBox]::Show("ERROR : The password you entered doesnot meet the complexity set in the Password Policy" )
break
else
$error2= [System.Windows.Forms.MessageBox]::Show("ERROR : passwords donot match")
I am getting issue when The password complexity error is coming. It is showing up the error in the catch, but it is creating the account in AD and disabling it. 
What I want is if any error is found and caught in the catch, then the user should not be created. How to do that?
Please provide your valuable suggestions and help me out
Naveen Basati

This is a good way to get teh paassword to abort when it fails the test.
function Test-Password{
Param($Password)
Try{
$pwd=ConvertTo-SecureString $Password -AsPlainText -force
Set-ADAccountPassword testuser11 -NewPassword $pwd –Reset
# it worked so return the encrypted password
$pwd
Catch{
Throw $_
$sam = "13653123"
if(get-aduser -Filter "SamAccountName -eq $sam"){
Write-Host 'User already exists' -ForegroundColor green
}else{
Try{
$pwdText='x123!heLno34' # 3 levels of compexity plus length > 9
$pwd=Test-Password $pwdText
$given='Jack'
$surname='Sparrow'
$Initials='Z'
$Department='1260'
$title='AM'
$props=@{
SamAccountName=$sam
UserPrincipalName="$[email protected]"
GivenName=$given
Initials=$Initials
Name="$given $initials $surname"
DisplayName="$given $initials $surname"
Title=$title
Department=$Department
Office=$Department
Path='OU=TestOU,DC=testnet,DC=local'
AccountPassword=$pwd
Enabled=$True
PasswordNeverExpires=$False
New-ADUser @props -ErrorAction Stop
Catch{
throw $_
We just re-throw the error and it propagates to the outer try/catch block.
¯\_(ツ)_/¯

Similar Messages

  • Error while creating new user in Oracle 11i EBS

    I am getting following error while creating new user. How solve this issue?
    “Unable to load java class % specified profile option SIGNON_PASSWORD_CUSTOM. Please verify that the class exists and that it implements the java interface oracle.apps.fnd.security.PasswordValidation”.

    Following is the text from Note for Custom Password Validation logic:
    Customers who wish to use their own password validation logic may do
      so by writing their own Java classes that implement the
      oracle.apps.fnd.security.PasswordValidation Java interface.  The
      interface requires 3 methods to be implemented:
      1) public boolean validate(String user, String password)
        - This method takes a username and password, and then returns true
      or false, indicating whether the user's password is valid or invalid,
      respectively.
      2) public String getErrorStackMessageName()
        - This method returns the name of the message to display when the
      user's password is deemed invalid (i.e., the validate() method returns
      false).
      3) public String getErrorStackApplicationName()
        - This method returns the application shortname for the
      aforementioned error message.
      After writing the Java class to perform customized password
      validation, the customer must then set the value of the profile option
      SIGNON_PASSWORD_CUSTOM to be the full name of the class.  If, for
      example, the name of the Java class is
      oracle.apps.fnd.security.AppsPasswordValidation, then the value of the
      SIGNON_PASSWORD_CUSTOM profile option must be
      oracle.apps.fnd.security.AppsPasswordValidation.  Note that AOL/J
      will attempt to load this class dynamically.  Hence it is necessary to
      make the class accessible by AOL/J.  This means that in Forms, the
      class must first be loaded into the database using the loadjava
      command.
    You will need to apply the following patches for 11.5.1:
       1344802
       1363919
       1472974
       1351004
       1377615
    You will need to apply the following patches for 11.5.2:
       1377615

  • Old user account not accessible - Had to create new user account

    Why was I forced to create a new user account in order to access Apple discussions? The last time I had posted to Apple discussions was 11/06. From the emails notifying me of replies to my post, I can still go to the link where my question and the replies are. Last week I wanted to post another question. Instead I encountered a circular problem. Every time I tried to log in to discussions with my Apple ID and password (the same as my .Mac name and password, which were working fine for accessing .Mac), I was told that there was an error in my password. When I tried again, I was repeatedly re-directed to a "create new user account" web page that listed my .Mac email address as my Apple ID, as it should have. I tried to re-create my old user account with my own [real] name (as before) and was told that name was in use! Of course, it was me! (I had always used by real first name and surname as my name on Apple discussions.) So finally, very frustrated, I created a new name, a nickname, for discussions, and it worked. Now, all my previous posts are gone. It's as if I didn't exist in the Apple world until today, 9/16/07, but I originally had established my user account in 2004. I tried asking about this in a phone call to Apple support, but I was re-directed to the .Mac web site. Then I posted a question at .Mac feedback to no avail. I had a feeling that as soon as I "obeyed" and created a new user account that wouldn't be recognized as myself, my past posts would be sent into oblivion. I don't like losing all my previous posts that were attached to my user account. I have found this problem very frustrating and would really like an explanation.

    Hi decemberbaby,
    Try this procedure.
    Delete all the Apple Cookies in your browser, and empty the Cache.
    Go here Discussions Sign In, and try logging in with your original Apple ID again.
    If that still doesn't work, delete the Cookies again, and go to My Info, and log in with the original Apple ID.
    If you get the error message "Your Apple ID or password was entered incorrectly.", click on "Did you forget your password? Click here for assistance".
    On the page that opens, you can also click on "Forget your Apple ID
    ali b

  • Creating new user in enterprise portal 7 .0

    Hi,
    I have installed enterprise portal 7.0 and backend is ECC 6.0 on windows 2003.i have logged with J2EE_ADMIN user.when i am trying to create new user in EP7.0 ,i got this problem.(an error occured,contact system administrator).please help me.

    Hi,
    Go to http://<server>:5<instance no>00
    Click on User Management. After login, go to Configuration tab and there you can check.
    Thanks
    Sunny

  • Error while creating new user

    Hi
    I HAVE LOGGED INTO oracle Portal with user : portal30 passwd : portal30.
    After selecteing the administer tab when i click on create new users I am getting error
    Error: (WWC-00000) with a back link ( which does not work ). I didn't get anything other than this on screen.
    I have tried to found out the soln but never succeded. What you think would be the reason for getting this error?
    do tell me on [email protected]
    Regards and thanks in advance
    Kedar

    Kedar,
    You may be able to find help on this by searching the 9iAS Portal forum, this forum is for questons relating specifically related to the PDK.
    thanks,
    Sue

  • [syntax_error] in Creating New User - After applying SP ABAP & Basis lv 8

    Hi Gurus.
    actually I already created message to SAP regarding this. but i havent receieve any respond. I post here just in case maybe I can have immediate solution from you guys..
    I have 2 system HLC and MFG
    which is using same OS and DB
    DB Information
    DB client lib.     SQL_Server_8.00
    DB releases        MSSQL 7.00.699 or higher, MSSQL 8.00.194
    DBSL version       700.08
    DBSL Patch Level   144
    System Information
    SAP versions       700
    Operating System   Windows NT 5.0, Windows NT 5.1, Windows NT 5.2, Wi
    OP release         5.2
    which have same Kernel and SP patches
    Kernel release    700
    Sup.Pkg lvl.      146
    SAP_ABA     700     0008     SAPKA70008
    SAP_BASIS     700     0008     SAPKB70008
    ST-PI 2005_1_700     0006     SAPKITLQI6
    PI_BASIS     2005_1_700     0005     SAPKIPYJ75
    Problem
    previously both of the system HLC and MFG is in level 6 SP ABAP and BASIS
    when i try to create EWA report for both of them, i have missing module in the report
    and i read a note that i need to upgrade to level 8.
    when i upgrade both of them to level 7, then i run sgen and there are no problem on both system
    but when i upgrade both of them to level 8
    in my MFG system, i can run sgen with no problem.
    in my HLC system, i run sgen and it take a long time to validate the programs which are need to be recompiled. so i never run sgen to recompile on HLC system after i update the SP to level 8. but i believe this shouldnt be an issue.
    the day after i update the SP, one of my user raise an issue.
    (same issue is not happened in MFG system only in HLC system)
    when we try to create new user..
    SU01 -> create new user -> fill all the details -> save -> abap dumps
      Error in the ABAP Application Program
      The current ABAP program "/SAPSLL/CL_IM_BP_ADDRESS======CP" had to be
       terminated because it has
      come across a statement that unfortunately cannot be executed.
      The following syntax error occurred in program "/SAPSLL/SAPLBP_ADDRESS " in
       include "/SAPSLL/LBP_ADDRESSTOP " in
      line 22:
      "Statement "/SAPSLL/DEBUG_DATA" is not defined. Check your spelling . ."
      The include has been created and last changed by:
      Created by: "SAP "
      Last changed by: "SAP "

    Hi all
    problem is solved..
    after doing some debugging, we found out
    there are some missing entries in table TRMAC
    so i just copy the missing entries from my MFG server to HLC server since they are both in same condition.
    now i am wondering why do the support package miss to enter the rows in TRMAC table >.<
    SAPache man..

  • Not able to create new users or groups

    hi all,
    We have configured multiple LDAPs by changing XML file.
    But now we are not able to create new users or groups.It is giving error saying that "Adapter is configured as read-only"
    Can anybody help me out in this problem.
    Thanking You,
    Amol.

    For multiple LDAPs to work we have downloaded the Xml file namely "Flat hierarchy + Database "
    We made the necessary changes and then uploaded it.
    Now we want to create users or groups in portal-database and not in LDAP. But it is throwing error saying that "Adapter is read only". We suppose that it is trying to create users and groups in LDAP.
    So can anyone help us to create users or groups in portal-database.
    Thanking You,
    Amol.

  • Problem with creating new user in portal = portlet is not visible

    Hi,
    I've got a problem with creating new users in portal. In the Administer tab of the builder is the user portlet not visible.
    How can I make this portlet visible?
    Please Help
    thank you...
    Gilbert

    Hi..my problem slightly similar.
    I created one new user, and didn't select anything from "Public Groups Assignment" and "Privilege Assignment" for him.
    I expect the user will be a public user.
    But, when he try to logged in the portal,
    He cannot see all the PORTLETS related to database values..
    All he can see just LINKS -that all in my portal right now beside the report from database that the user cannot see :)
    So, what did i do wrong?
    Plz Advise, and thanks.

  • Problem in creating new user

    Hai all,
    I am new to Portals, when I am trying to create a new user it was displayed as "<b>User could not be created</b>". What is the actual process of creating a new user and how to work with that user. I have gone through some of the discussions in the form but unable to create the new one.
    Can any help on this please.
    Suma...

    Hi,
    Actual process of creating the user is
    logon to http://server:port/irj
    goto user administration
    goto users
    click create new user
    fill up all mandatory fields, define the data as configured (for e.g. password alphanumeric etc
    click create.
    You should be able to create the user.
    If this process doesnot work check ur UME store settings? if it is in LDAP server check if your LDAP is ab to craete new users etc? you can also try to create new users from Visual Admin .
    logoff and then try to login with the newly created user it should show password expire screen.
    regards,
    Rohin Aggarwal

  • How to create new user with more than one default folder

    hi
    A new user created in OCS has only one default folder(Inbox).
    I want to create new user with customized default folder.
    for example:
    a new user has more than one default folder(Inbox,Outbox,Draft,Dustbin...)
    And also I want to automaticly enable the functions:
    When sending messages, place a copy in Outbox
    Keep message drafts in Draft
    Move deleted messages to Dustbin
    who know that?
    thanks

    The same reason that Apple and 3rd Party vendors put multi-size templates in one file I expect. I am trying to construct an in-house standard template for use in our company, and it is easier to manage if there is only one file to send to people rather than many - both initially and for subsequent edits / updates to the template.
    Of course it would be possible to create several templates (one for each size). But since it is clear that templates can be combined, it appears sensible to do this - unless the doing of it is horridly complicated

  • Creating New Users for RDBMS realm

    I am currently creating new users in the RDBMS realm
    by an EJB that will insert into the "Users" table. Is this
    the correct way to create users or should I be calling
    methods on classes in examples.security.RDBMSRealm?
    Thanks
    Bill.

    Thanks a lot for the guideline.
    I can able to create multiple users using Import option of the user administration but i have one more question regarding the same.
    What about the password setting of these newly created users. Or can the set the password field in test file?? Because when we export the user, it is not showing any Password field.
    Thanks & Regards,
    Prashant

  • Can't create new users in Administration Services Console

    Hi,
    I am following directions in the Essbase DBA guide for creating new users, as it says you must create a partition user to work with Samppart and Sampeast applications. It tells me to log on to Administration Services Console, go to the Administration Server, and right-click on users to create a new user. However, when I right-click, the option to Create New User is light grey and not clickable, neither is the option to refresh users. Can anyone tell me why I can't create a new user? I am logged in with the username: admin password: password that I set during configuration and that should be the Administrative account.

    Hi,
    What version are you using? If it is 9 then you need to create the user in shared services. I just checked and the option to create a user is greyed out for me too and I am an admin.
    It sounds like you haven't externalised the users which is why the option to do a refresh is not there.
    Thanks,
    Nathan

  • Solaris 10 and create new user

    I have got solaris 10, I want to create new user , ( Through command line and GUI), is there any guidline on net shows me step by step how to create user ?
    I had created user, but I could not login through that user, I was able to login as root only.

    I tried many things, but I still could not login, therefore I asked if you can post me some link show me step by step , I reapt step by step how to create new user in Solaris 10,,,,,,,,,,should step by step,,,,,I know how to use: useradd and chown and mkdir in /export/home,,,,,,etc.
    I relly appreciate if there is any link dives details for creating new user, because I could not find.

  • Ess error & unable to create new user

    hi gurus...
    i new to portal and i m facing problem in ess and user creation ...
    1 .)   my ess is showing the following error
    Service cannot be reached
    What has happened?
    URL http://wind:8000/webdynpro/dispatcher/sap.com/pcui_gp~xssutils/XssMenu call was terminated because the corresponding service is not available.
    Note
    The termination occurred in system EC1 with error code 404 and for the reason Not found.
    The selected virtual host was 0 .
    What can I do?
    Please select a valid URL.
    If you do not yet have a user ID, contact your system administrator.
    ErrorCode:ICF-NF-http-c:000-u:SAPSYS-l:E-i:wind_EC1_00-v:0-s:404-r:Notfound
    HTTP 404 - Not found
    Your SAP Internet Communication Framework Team
    2) In user management .. when i m clicking on create new user tab... it shows an error and says "An error occurred; contact your system administrator "   while i m the admin here and having all the right with me.
    pls help me regarding this....

    Hi,
    Did you install pcui_gp sca file suring deployment of ESS/MSS business package.?I think that sca file is missing
    1 .) my ess is showing the following error
    Service cannot be reached
    What has happened?
    URL http://wind:8000/webdynpro/dispatcher/sap.com/pcui_gp~xssutils/XssMenu call was terminated because the corresponding service is not available.
    2) In user management .. when i m clicking on create new user tab... it shows an error and says "An error occurred; contact your system administrator " while i m the admin here and having all the right with me.
    Is data dource configured to ABAP? then create in abap system such that users will be visible into portal.
    Regards,
    Koti Reddy

  • How to create new user for OBIEE presentation service

    Hello Guys
    I now only have 2 users on my OBIEE, demo1, demo2.. Now I'd like to create a new user call A and make this new user able to log on to OBIEE presenation service..
    So I went to the RPD admin tool and created new user there and gave password. It was done online mode and I checked out..
    I am able to login to admin tool with the new user account, but when I go to presentation service, I am not able to see this new user nor would I be able to log on using the new user account..
    So how does this work? If I wanted to create a new user and let it access dashboard, I'd I do it
    Any pointer will be greatly appreciated
    Thanks

    Hi.
    actually there is no option available in presentation service to create user. There you can just delete user and create and delete the groups.
    Anyhow, you said you have created a user in rpd.
    To see this user in answers, you must login into answers with this user once.
    are you able to login with the newly created user?
    (As you said you done the creation of user in online mode, this may not effect to the answers)
    if not, just login with administrator into answers, click on reload server metadata, then log off from there.
    Now, try to login with the new user. You may able to login.
    OR
    just restart your BI Server services.

Maybe you are looking for