Hmm...This Might Work

Solutions from a day long since past
posts - 20, comments - 7, trackbacks - 0

AD User Account Creation–Script

I’m throwing this script out there for any developers or admins who are seeking a quick SharePoint focused script for user account creation.

In my environment we’re working towards automated unattended install of SharePoint, including account creation. AutoSPInstaller is cool
but it seems too complicated for me. Put another way, if I’m going to spend time learning I’m choosing to learn PowerShell and SharePoint
in more detail.

With that said, here is my script. This script could easily import from a CSV (or other file), read a SharePoint List, or any other means of
input. For the purpose of an example, an array is used.

 

#Make Use Of An Array Just for example. This could easily be a csv but since this was for dev it was easier

#In Case of CSV Column Order would be "SamAccountNAme,FName,LName,Description,Password

#$UserList = Import-CSV -Path <csv path here>

$UserList = @(

@("<SamAccountName>","<FName>","<LName>","<Description>","<PassworD>"),

@("<SamAccountName1>","<FName1>","<LName1>","<Description1>","<PassworD1>"),

@("<SamAccountName2>","<FName2>","<LName2>","<Description2>","<PassworD2>")

)

#Loop Through Each Nested Array

ForEach ($User in $UserList) {

$SamAccountName = $User[0]#(Read-Host -Prompt "Please Enter SamAccountName")

#Check To See If SamAccountName Already Exists, If It Doesnt Create It

If (!(Get-ADUser -Filter {SamAccountNAme -eq $SamAccountName})){

    $OUPath = "OU=<OUName>,OU=<OUName>,DC=<DomainRoot>,DC=<dot suffix>"

    $DomainSuffix = "@<domain.org>"

    $FName = $User[1]

    $LName = $User[2]

    $Description = $User[3]

    $PassWord = ConvertTo-SecureString ($User[4]) -AsPlainText -Force #(Read-Host -Prompt "Enter Account Password" -AsSecureString)

    New-ADUser -Name ($FName+" "+$LName) -SamAccountName $SamAccountName -GivenName $FName -Surname $LName -DisplayName ($FName+" "+$LName) -Path $OUPath -UserPrincipalName ($SamAccountName+$domainsuffix) -Description $Description -AccountPassword $PassWord  -PasswordNeverExpires:$true -Enabled:$true

    }

Else

    {

    Write-Host "$SamAccountName already exists within AD. It will not be created"

    }

}

 

Print | posted on Thursday, May 29, 2014 4:18 PM | Filed Under [ SharePoint ActiveDirectory SharePoint 2010 Powershell SharePoint 2013 ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 8 and type the answer here:

Powered by: