Skip to content

Instantly share code, notes, and snippets.

@macostag
Created November 26, 2017 18:43
Show Gist options
  • Save macostag/021626d5dd83cd9a250a2184765c7604 to your computer and use it in GitHub Desktop.
Save macostag/021626d5dd83cd9a250a2184765c7604 to your computer and use it in GitHub Desktop.
Import Active Directory users from CSV file.
Import-Module ActiveDirectory
$DomDN = (Get-ADDomain).DistinguishedName
$forest = (Get-ADDomain).Forest
$Ou = Get-ADOrganizationalUnit -Filter 'Name -like "Usuarios"'
$file = Import-Csv .\Users.csv
$data = $File | select @{Name="Name";Expression={$_.GivenName + " " + $_.Surname}},
@{Name="SamAccountName"; Expression={$_.Username}},
@{Name="UserPrincipalName"; Expression={$_.Username +"@" + $forest}},
@{Name="GivenName"; Expression={$_.GivenName}},
@{Name="Surname"; Expression={$_.Surname}},
@{Name="DisplayName"; Expression={$_.GivenName + " " + $_.Surname}},
@{Name="AccountPassword"; Expression={ (Convertto-SecureString -Force -AsPlainText $_.password)}},
@{Name="Enabled"; Expression={$true}},
@{Name="PasswordNeverExpires"; Expression={$True}},
@{Name="Path";Expression={$Ou.DistinguishedName}},
@{Name="EmailAddress"; Expression={$_.EmailAddress}}
$data | New-ADUser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment