Miscbrah Posted April 2, 2012 Posted April 2, 2012 (edited) Hi again folks. Thanks tons with the script help in the past! Just needed to drop this one on you all and see if there's any way to do this... I have at the moment a list of groups and group types I'd like to create in a new domain, by which I mean a spreadsheet with the AD container destination for the groupOU for the group, the name I'd like to give to the group and the type of group by number, as in 'Global Security' are 2147483646, 'Universal Security' are 2147483640 etc... (got the output from THIS PAGE HERE) I also have a list of usernames for each group, but know how to add those later when the groups are created. HUGE thanks if anyone's able to help me out with this! Really kinda stuck now... Cheers for reading! Edited April 2, 2012 by Miscbrah
Miscbrah Posted April 2, 2012 Author Posted April 2, 2012 (edited) Right, I've found something I didn't consider before in a Powershell script. Now I'm TOTALLY new to Powershell and not quite certain I've got this right, just putting this out there to see if anyone can follow my train of thought and if it happens to be the answer then even better Also, if anyone follows my thinking in the future then you'll know what my brain was up to. I'll be running one Powershell command for each group type. Types of group follow with their respective numbers: Domain Local Security -2147483644 Global Security -2147483646 Universal Security -2147483640 Domain Local Distribution 2 Global Distribution 4 Universal Distribution 8 First up my .csv file for creating the Global Security groups first of all, the imaginatively titled groupimport.csv a thrilling extract of which will look something like this: name,groupType Library Staff,-2147483646 Business Studies Staff,-2147483646 Music Staff,-2147483646 ... Now at this point I wonder if those numbers will be what it wants or the names of the new group types, but that's easy enough to ctrl+H and change should I need to. Anyway, command follows. This is where I want to reference that file up there. I *think* this is the way to do it... $path = "c:\groupimport.csv" $csv = Import-csv -path $path foreach($line in $csv) { New-ADGroup -Name $line.name -Path "ou=groups,dc=mydomain,dc=com" -groupScope $line.groupType } (where 'mydomain' is set up for my domain as you might think Also just for creating Global Security groups I don't need to specify a group type as this is the default I think. I read that somewhere, but going to set the type anyway.) So, this is where I am. Am I silly or am I barking up something tree-like? Edited April 2, 2012 by Miscbrah
deano Posted April 2, 2012 Posted April 2, 2012 have you seen the wisesoft website. I have used their spreadsheet before
Miscbrah Posted April 2, 2012 Author Posted April 2, 2012 (edited) Hi Deano - yeah I've seen the website (which is awesome tbh) and recently had a look at that spreadsheet thing. Not entirely sure why I overlooked it now, but I remember being baffled by it or some part of it. I'll have another check back. EDIT - given the scripts for AD section a rummage and there's nothing there that quite does what I want to do here. Again though, that's a superb resource that site. Edited April 2, 2012 by Miscbrah
ascott2 Posted April 2, 2012 Posted April 2, 2012 New-AD Group uses the -GroupScope Global/Domain etc and -GroupCategory Security/Distribution so you would need to fill in both. eg New-ADGroup -Name NewGroupName -Path "ou=groups,dc=mydomain,dc=com" -groupScope Global - groupCategory Distribution 1
Miscbrah Posted April 2, 2012 Author Posted April 2, 2012 Ah sweet, thanks! Well the boss is going to back up the DC and to be honest I have found other work to do for the rest of the day, which conveniently allows me to chicken out of this until tomorrow. I'll have a check back here and a bit more of a read up tonight and let y'all know if I do it or set the domain alight or something
Miscbrah Posted April 3, 2012 Author Posted April 3, 2012 Oh well. This is what I came up with so far, and which doesn't work: $path = "c:\adgroups\globalsecurity.csv" $csv = Import-csv -path $path foreach($line in $csv) { New-ADGroup -Name $line.name -Path "ou=security,ou=groups,ou=BLAHBLAH,dc=BLAHBLAH,dc=BLAHBLAH,dc=sch,dc=uk" -groupScope Global -groupCategory Security } Write-Host "Press any key to continue..." $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") My .csv file only has one column in it now. As I'm running one script for each group type, I don't need it to reference that part anymore. I've also *tried* to insert a pause in there so I can read the fleeting bunch of red writing in the Powershell window before that disappears, but that doesn't work either. Urgh. Anyone got any pointers for me? Am I nearly there or miles out?
Miscbrah Posted April 3, 2012 Author Posted April 3, 2012 ...And I'm thinking to myself "PLEASE nobody spot the obvious mistake..." Yeah so enabling the security to actually allow scripts to run at all is a good idea huh. It works! Thanks for all the help! Just so anyone stumbling across this is clear, the .csv file looks pretty much like: name Toilet Cleaners Pastry Makers SLT Class Teachers Upper Class Teachers etc One line for each group name I'd like, and just renaming the parts of the command in the .ps1 file (powershell script file extension) for groupScope and groupCategory.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now