Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create Groups based on Text File

Posted on 2011-03-07
3
Medium Priority
?
960 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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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