Solved

Create Groups based on Text File

Posted on 2011-03-07
3
939 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

22 Experts available now in Live!

Get 1:1 Help Now