G
G
GLaNIK2015-02-02 09:53:40
PowerShell
GLaNIK, 2015-02-02 09:53:40

How to add users from CSV file in PowerShell?

Good afternoon!
The problem arose, not otherwise than such ...
All my adult life I was fiddling with Linux, and the Linux domain.
But, suddenly, neither light nor dawn, VMware Horizon was brought into the institution, which works only with Windows domains, and then - from 2012
And now, in fact, the task is to overtake all users exactly there.
Fortunately, there is a CSV file from which everything was done.
It has the following format:
lastname;firstname;cohort1;username;password;email
Where cohort1 is a group of users.
Which, in this case, can be excluded. And not only that - to add, it is also necessary to set the address of the directory of profiles on the CIFS ball to all users.
Example:
Pupkin;Vasily Kamushkovich;9sk-13;9sk-13-1;SecretWord;[email protected]
A quick googling showed that everything would be possible with PowerShell.
But the trial poking made it clear that in the case of a CSV file different from the example, I am definitely stumbling somewhere.
Where ... I would be extremely grateful for any help in this matter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nikitin, 2015-02-02
@GLaNIK

I think you need something like the following script:

$userscsv = Get-Content -Path "C:\Temp\users.csv" -Encoding UTF8

$users = ConvertFrom-Csv -InputObject $userscsv -Delimiter ';'

foreach ($user in $users) {

    New-ADUser -SamAccountName $user.username -Surname $user.lastname -GivenName $user.firstname -AccountPassword $user.password -EmailAddress $user.email

}

A full description of the New-ADUser cmdlet is available on TechNet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question