PowerShell Command to create bulk users in Active Directory



User Template format 





# Import users from CSV

$users = Import-Csv -Path "C:\temp\users.csv"


foreach ($user in $users) {

$samAccountName = $user.LoginID

$displayName = $user.DisplayName

$email = $user.Email

$depatment=$User.Department

$password = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force


    # Create user

New-ADUser `

-Name $displayName `

-SamAccountName $samAccountName `

-UserPrincipalName "$samAccountName@ads.com" `

-DisplayName $displayName `

-EmailAddress $email `

-Department $depatment `

-AccountPassword $password `

-Enabled $true `

-Path "OU=VDI,DC=ads,DC=com"

    

Write-Host "Created user: $displayName ($samAccountName)"

}

No comments:

Post a Comment

Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...