Here's a sample PowerShell script for importing users in bulk into Active Directory (AD). It configures these AD fields:
- SamAccountName
- UserPrincipalName
- GivenName
- Initials
- Surname
- DisplayName
- Name
- Description
- Company
- StreetAddress
- City
- State
- PostalCode
- OfficePhone
- Fax
- EmailAddress
- AccountPassword
- ChangePasswordAtLogon
- PasswordNeverExpires
- Enabled
- PassThru
Referencesimport-csv c:\temp\100.csv | foreach-object {New-ADUser -SamAccountName $_.SAMAccountName -UserPrincipalName $_.SAMAccountName -GivenName $_.givenName -Initials $_.Initials -Surname $_.Surname -DisplayName $_.DisplayName -Name ($_.givenName + $_.Initials + $_.Surname) -Description $_.Description -Company $_.Company -StreetAddress $_.StreetAddress -City $_.City -State $_.State -PostalCode $_.PostalCode -OfficePhone $_.OfficePhone -Fax $_.Fax -EmailAddress $_.EmailAddress -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -ChangePasswordAtLogon $False -PasswordNeverExpires $True -Enabled $True -PassThru -WhatIf}
- What's New in AD DS: Active Directory Module for Windows PowerShell
- Active Directory Management with PowerShell in Windows Server 2008 R2
- Build a SharePoint Server 2010 Two-Tier Dev Environment on Windows 2008 R2
- How to generate complex AD account metrics
- Import-Csv
- Active Directory Module for Windows PowerShell – Quick start guide
Notes
- Execute this in an elevated shell.
- Execute Import-Module ActiveDirectory before running this script.
No comments:
Post a Comment