Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...you guys have given us a way of asking a question and getting some very timely feedback from other users so we don't have to re-invent the wheel time and again..."

Geography

Where in the world do Tek-Tips members come from?

Powershell and Creating Groups using CSV

Absolution84 (TechnicalUser)
6 Jun 12 9:58
Hi everyone,

I am new on this forum and also to powershell.

I have a question which I cannot seem to find an answer for elsewhere on the web.

If I have a csv file which looks like.....

objectClass sAMAccountName DN
group Customer Services CN=Customer Services,OU=User Groups,dc=example,dc=co,dc=uk
group Finance CN=Finance,OU=User Groups,dc=example,dc=co,dc=uk
group Finance Managers CN=Finance Managers,OU=User Groups,dc=example,dc=co,dc=uk
group Sales CN=Sales,OU=User Groups,dc=example,dc=co,dc=uk

How do import groups using the revelant information i.e. sAMAccountName,DN?

I dont know many of the ins and outs of powershell import-csv so I'm a little stumped.

If someone could show me a a sample script or give some advice, I would really appreciate it.

Thank you in advance for any replies.


58sniper (MIS)
6 Jun 12 20:52
I haven't tested this, but here's the steps that should work

CODE --> PowerShell

$domainName = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name $domainName = $domainName -replace "\.", ",dc=" $ou = [ADSI] "LDAP://ou=User Groups,dc=$domainName" $groups = Import-Csv mygroups.csv ForEach ($group in $groups){ $newgroup = $ou.Create("group", "cn=$sAMAccountName") $newgroup.Put("SamAccountName", $sAMAccountName) $newgroup.Put("groupType", -2147483640) $newgroup.SetInfo() }

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close