0

PowerShell - Create AD Groups then Populate Them from CSV

by Jim 16. October 2011 17:57

In my previous post, I explained how to export a .CSV for each group in an OU.  This gives you a .CSV for each group which is named the same as the group name.

  • Some Group 1.csv
  • Some Group 2.csv
  • Some Group 3.csv
  • Some Group N.csv

Now, I need to create those Groups in a new AD.  Here is the script that I used:

Get-ChildItem | foreach { echo $_.Basename } | ForEach-Object { dsadd group -scope u "cn=$_,OU=Groups,OU=Some OU,DC=SubDomain,DC=Domain,DC=TLD" }

This script calls the program DSADD and passes it the correct name (minus the .csv) which is then used to create the Groups.

Next, we run a similar script that walks through those same .CSV's and adds the users to the group with the same name as the .CSV.

Get-ChildItem | foreach { $GN = $_.BaseName; Import-Csv $_ } | foreach { Add-ADGroupMember -Identity $GN -Members $_.SamAccountName }

This works wonderfully well if the column titled SamAccountName has the correct usernames in it.

Tags: , , , ,

PowerShell

0

PowerShell - Create Users from CSV

by Jim 16. October 2011 11:23

This script creates users via Powershell.  I had to create 500 users in a new Active Directory domain that I had previously exported from an old domain.  This script can be run from the command line in PowerShell.  I have attached a .TXT file with the script if you would like to download it.

You will need a .CSV file with the following columns:

  • Alias
  • UPN
  • Name
  • DisplayName
  • FirstName
  • LastName
  • OU

Import-Csv 'Users.csv' | ForEach-Object { New-ADUser -SamAccountName $_.Alias -UserPrincipalName $_.UPN -Name $_.Name -DisplayName $_.displayname -GivenName $_.FirstName -Surname $_.LastName -Path $_.OU -AccountPassword (ConvertTo-SecureString "Some!Password" -AsPlainText -Force) -Enabled $true -PasswordNeverExpires $false -PassThru } > Import.log

Create users from CSV.txt (349.00 bytes)

Tags: , , , ,

PowerShell

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft