Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Powershell and Creating Groups using CSV

Powershell and Creating Groups using CSV

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.

RE: Powershell and Creating Groups using CSV

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 Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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