Solved

Create Groups based on Text File

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to filter result in PowerShell 10 58
AD Cleanup by EmployeeID 11 49
PowerShell script to remove string in xml file 8 21
write-output without carrier return 1 16
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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