Author Posts

March 16, 2016 at 6:53 am

Hello,

I am building delegation groups for a new OU structure design and the naming convention is based on the group role and site location (ie ADL- admin local, newyork – site. ) I would like to know if it is possible to create new groups based on the different sites from a text file/csv with the group name added to a string to conform with the naming convention?

This is what I had in mind:

$strGrpSite = Get-Content .\Sites.txt

$strGrpSite|Foreach{
New-ADGroup "ADL-"+$_"_Create" -GroupScope DomainLocal -GroupCategory Security -path "OU=OU=TestOU,DC=testdomain,DC=com"
}

The intended output would be:
New group created: ADL-newyork_Create

What I do not know is the correct syntax to join the strings to form the groupname.

March 16, 2016 at 7:17 am

Nevermind, I figured it out..

Sites.txt contains:
newyork
miami
london

$strGrpSite = Get-Content .\Sites.txt

$strGrpSite|Foreach{
$strGrpName = -join("ADL-","$_","_Create"
New-ADGroup $strGrpName -GroupScope DomainLocal -GroupCategory Security -path "OU=OU=TestOU,DC=testdomain,DC=com"
}

Result Output:

ADL-newyork_Create
ADL-miami_Create
ADL-london_Create

March 16, 2016 at 7:24 am

Try something like this:
New-ADGroup -name "ADL-$strgroup_Create"

March 16, 2016 at 7:46 am

That won't work since Powershell will consider "$strgroup_Create" as the whole variable name instead of separate strings. I have already tested this out and it only created the "ADL-" part.

This definitely worked though:
$strGrpName = -join("ADL-","$_","_Create")

Thanks anyway for the response.

Cheers!