Solved

Create Groups based on Text File

Posted on 2011-03-07
3
945 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

733 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