Created
August 22, 2018 07:50
-
-
Save DXPetti/586d54bd7fdf229fea44605fe516cea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import list of Users From CSV into $Userlist | |
$UserList=IMPORT-CSV driveletter:\pathtofile.csv | |
# Step through Each Item in the List | |
FOREACH ($Person in $UserList) { | |
# Build Username | |
$Username=$Person.Username | |
# Build Password from Firstname and Lastname | |
$Password=$Person.Firstname+$Person.Lastname | |
# Build the Displayname | |
$Name=$Person.Firstname+” “+$Person.Lastname | |
# Build and define Domain name | |
$Domain="@yourdomainhere.com" | |
# Build User Principal Name | |
$UPN=$Username+$Domain | |
# Build and define Home Directory path | |
$HDrive="\\uncpathtohomeshare\" | |
# Build and define which Organizational Unit to create User inside | |
$OU="OU=organizationunitofyourchoice,DC=yourdomainhere,DC=com" | |
# Create Account in Active Directory (AND HERE...WE...GO!) | |
New-ADUser -Name $Name –GivenName $Person.Firstname –Surname $Person.Lastname –DisplayName $Name –SamAccountName $Username -HomeDrive "H:" -HomeDirectory $HDrive –UserPrincipalName $UPN -Path $OU | |
# Set Password | |
Set-ADAccountPassword -Identity $Username -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force) | |
# Add User to Security Groups | |
Add-ADPrincipalGroupMembership -Identity $Username -MemberOf "security group a","security group b" | |
# Enable Account | |
Enable-ADAccount -Identity $Username | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment