Posts tagged ‘csv’

How to import Users to Windows 2012 Active Directory using PowerShell

Hi Guys

In many AD installations I do come across requirements  to create multiple users in Active Directory(More than 200 in many cases) .In these cases we could use the below mentioned CSV template and use the PS command to directly import the users in  to Active Directory.

users

Here the Path value is pointing to the OU that you want to place the users  in the Active Directory , which could be find using the Attribute Editor of the OU(We need to enable the Advance Feature in the ADUC Management Console)

PS Command Syntax
Import-CSV C:\anyname.csv | New-ADUser –AccountPassword (ConvertTo-SecureString –AsPlaintext “any complex password” –Force) –PassThru | Enable-ADAccount.

Example:

Import-CSV C:\Users_1.csv | New-ADUser –AccountPassword (ConvertTo-SecureString –AsPlaintext “P@ssw0rd” –Force) –PassThru | Enable-ADAccount

 

Update2:

I am including here another method to achieve the same.

# Prepare the CSV file as per below(You could any details as much as you want, by adding the correct attribute.)

firstname,lastname,username,email,department,password,jobtitle,company,ou,Mobile

# Then run the below powershell.

+ You must change the active directory domain name.

+ You must change the csv file name.

+ Ensure that , you have given the proper DN namespace for the OU Value. Otherwise , the script will fail with the below error messages:

“No superior reference has been configured for the directory”

“New-ADUser : The object name has bad syntax”

 

===================================================================================

# Import active directory module for running AD cmdlets
Import-Module activedirectory

#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\test.csv

#Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below

$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$email = $User.email
$telephone = $User.Mobile
$jobtitle = $User.jobtitle
$company = $User.company
$department = $User.department
$Password = $User.Password

#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning “A user account with username $Username already exist in Active Directory.”
}
else
{
#User does not exist then proceed to create the new user account

#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName “$Username@vands.pro” `
-GivenName $Firstname `
-Surname $Lastname `
-Name “$Firstname $Lastname” `
-DisplayName “$Lastname, $Firstname” `
-Enabled $True `
-Path $OU `
-Company $company `
-EmailAddress $email `
-Mobile $telephone `
-Title $jobtitle `
-Description $jobtitle `
-Department $department `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True

}
}

===============================================================================

December 22, 2016 at 2:24 pm Leave a comment

How to migrate the Hyper-V CSV’s to a new Storage

Dear Folks

Recently we sold a VNX 5300 storage to our customer and his intention was to migrate the data from his old EMC AX4 5i Storage.

We proposed him the SAN based migration option but customer was resisting and we have to do it on the Windows level.

The Environment

2 Node Windows 2008 R2 Hyper-V Cluster CSV enabled.
Ax4 5i Storage
EMC Powerpath Free Edition installed on both hosts.
2 FC HBA

Steps Performed.

– Initialized the new storage
– Configured the new LUN’s
– Connected a new HBA’ (Because the server was having only single free PCIE slot)
– Assigned the LUN’s to both the server.
– Logged in to one of the server ( which was the current owner for the CSV)
– Added the LUN as disk via Storage from Failover Cluster Manager)
– Added as CSV (via Cluster Shared Volume from Failover Cluster Manager)
– Exported the Virtual Machine to the new location on the C:\ClusterVolume(Can be any name as per your environment)\NewFolder –>Which will point it to the new disk)
– Deleted the VM from the Hyper-V Manager
– Imported VM again from the new location via the Hyper-V Manager.(Do not change any options from the Import Wizard)
– Finally Changed the Quorrum drive to the new LUN on the Storage via Change Cluster Quorrum Settings from the Failover Cluster Manager)
– Removed the Old Storage
– Fixed the Additional HBA
– Removed EMC Powerpath
– Enabled MPIO

Voila everything went smooth as ice.

Hope this article is useful and incase if you need any additional information please do not hesitate to contact me.

February 6, 2014 at 8:07 am Leave a comment


Archives

Categories

Follow Hope you like it.. on WordPress.com

Blog Stats

  • 54,968 hits

%d bloggers like this: