New-aduser new USER command for PSAD commands!

Source: Internet
Author: User
Tags samaccountname

New-aduser new USER command for PSAD commands!
New-aduser


1. when we only need to create a user, we only need to write the following command. New-aduser-name raymond creates a single user named raymond, But it is strange that, our users are disabled. Why? It's easy, because he has no Password attribute


2. If you need to create an enabled account with complete user information, refer to the following information:
We want to create an OU account password with the name-last name-login term-UPN-display name-create a user. What should we do with these attributes. In fact, it's easy to use powershell. What should I do? Let me see:
New-aduser-samaccountname raymondxu-name xupeng-userprincipalnameraymondxu@pilot.com-displayname "Raymond Xu Peng"-path "ou = IT, dc = pilot, dc = com "-accountpassword (convertify-securestring" Admin909217 "-asplaintext-force)-enabled $ true


3. The above is the command for setting up a single user. Next we will create a random set of 100 users. The naming rule for users is user1 ..... User100, so that we can define 100 users. What should we do?
It is very simple, because it is based on the number to accumulate, you need to use the for statement in Powershell combined with new-aduser to achieve user batch creation, the Code is as follows:
For ($ I; I I-le 100; $ I ++)
{
$ Username = "user" + $ I;
New-aduser-name $ username;
}




After talking about batch creation of users with rules, most of our users will not have the same rules as above. Our users may be Zhang San and IT department. Li Si business department. Wang Wu administrative department. What should we do with such a user change. We first create a file for the user to be created, and then check whether the file can be imported into our Active Directory. To create some basic information to ensure that the user we have created is relatively complete. To avoid being too complicated, we write the code according to the standard method of writing code.

Name, samaccountname, displayname, UPN, path, department

Xupeng, xupeng, "raymond xu Peng", xupeng, it, Information Management Department

Xuefei, xufei, "sophie xu xufei", xufei, Administration Department

 

Next we save the file as CSV, and then we start to execute the following Powershell command. The foreach function is used in the command because of the need for round-robin, at the same time, we need to import the data into our Active Directory and use the import-csv command to import the data. Please refer to the following steps:

First, open the Powershell command line in the Active Directory:

We save the edited file as the Unicode mode of CSV. This step is very important. Otherwise, garbled characters will appear.

Next, let's perform operations step by step. First, we import the data into the memory:

$ Userlist = import-csv-path user.csv

 

Next let's take a look at the content of the variable userlist:

Next we will use the foreach command in combination with our User Creation command:
$userlist=import-csv -path user.csvforeach($user in$userlist){$ou="ou="+$user.path+",dc=pilot,dc=com";$upn=$user.upn+"@pilot.com";New-aduser -name $user.name-samaccountname $user.samaccountname -userprincipalname $upn -displayname -path$ou $user.displayname -accountpassword (convertto-securestring"Admin909217" -asplaintext -force) -enabled $true}

Let's look at the command execution result:

 

Of course, there are many friends who say this writing is too troublesome. We have a simple operation to make our script into a PS file and then we can call it directly. This idea is a good idea, but before doing this, we need to know what external call parameters are. We need to define our input parameters before PS. How can we define them? For the whole script, we need to apply a parameter when calling it, that is, the path of the imported file:

 

Param($location="d:\user.csv")$userlist=import-csv -path$locationforeach($user in$userlist){$ou="ou="+$user.path+",dc=pilot,dc=com";$upn=$user.upn+"@pilot.com";New-aduser -name $user.name-samaccountname $user.samaccountname -userprincipalname $upn -displayname -path$ou $user.displayname -accountpassword (convertto-securestring"Admin909217" -asplaintext -force) -enabled $true}

After saving the file as PS, we can execute the PS file to find the same effect as before. This script will be available on the CSDN download channel for you to download. The sample file will also be available in CSDN. You are welcome to download and use it.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.