How to create AD Groups via string+variable?


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

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.

Nevermind, I figured it out…

Sites.txt contains:

$strGrpSite = Get-Content .\Sites.txt

$strGrpName = -join(“ADL-”,"$_","_Create"
New-ADGroup $strGrpName -GroupScope DomainLocal -GroupCategory Security -path “OU=OU=TestOU,DC=testdomain,DC=com”

Result Output:


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

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.