Solved

Create Groups based on Text File

Posted on 2011-03-07
3
941 Views
Last Modified: 2012-05-11
Hello,

I am curious if someone could point me in a direction on creating a Powershell script to create groups and members.

Here is my scenario, I have a text file named Group1.txt.  Inside of Group1.txt, I have a list of users as follows:

John Doe
Jane Doe
Bob Johnson
Robert Smith

That is all that exists in the text file.  I am looking for a way to create a powershell script to create the Active Directory group based on the filename of the text file (Group1).  Then I would like to add members as they exist in the text files.  I have hundreds of these text files in a single directory, and need to find the fastest way possible of importing them into AD.

Thank you for any assistance you may be able to provide.
0
Comment
Question by:PhillipsPlastics
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 35058148
I would use the quest AD cmdlets

I ahve not tested so test first.

$groups = get-child-item c:\groups
$Groups |%{
$GrpName = $_.basename
new-qadgroup -name $grpname -parentcontainer "OU=Groups,DC=Domain,DC=local" -grouptype "security" -groupscope -"global"
$users = gc $_.fullname | %{add-qadgroupmember $grpname $_}
}
0
 

Author Comment

by:PhillipsPlastics
ID: 35058680
I do have the quest AD cmdlets, but it appears it can't run get-child-item??

[PS] C:\.\group.ps1
The term 'get-child-item' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\corym\group.ps1:1 char:25
+ $groups = get-child-item <<<<  c:\groups
    + CategoryInfo          : ObjectNotFound: (get-child-item:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

New-QADGroup : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is
not null or empty and then try the command again.
At C:\Users\corym\group.ps1:7 char:19
+ new-qadgroup -name <<<<  $grpname -parentcontainer "ou=groups,DC=company,DC=com" -grouptype "security" -groupscope -"g
lobal"
    + CategoryInfo          : InvalidData: (:) [New-QADGroup], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlet
   s.NewGroupCmdlet

Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\corym\group.ps1:9 char:12
+ $users = gc <<<<  $_.fullname | %{add-qadgroupmember $grpname $_}
    + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentC
   ommand
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 35059219
sorry that is a typo, should be
get-childitem
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
A procedure for exporting installed hotfix details of remote computers using powershell
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now