Automated Extensionname for each domain controllers

I need to populate a multi-value strings inside of the Extensionname attribute for all 30 domain controllers in Active Directory using 2 different domain name spaces FQDN, using powershell.

I am able to populate this string value with only 1 FQDN, domain name, & VIP name; but is not able to populate 2 different FQDN name spaces for the domain controllers, which throws syntax errors inside of the ISE.

Here is the task I'm trying to accomplish. "ExtensionName =  FQDN1.domain1.lab,Domain1.lab,FQDN2.domain2.lab,VIPName.lab"

Example of the script that is working is listed below.  But it only working for FQDN1 domain controllers name space.

$DCController = (Get-ADDomainController -Filter *).name

foreach($DC in $DCController){
Set-ADComputer -Identity $DC -Replace @{extensionName = $DC+"."+'domainname1.lab,domainname1.lab,VIPName.lab'}
}



Your help will much appreciated :)
JCJohnson76Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
All you need to do is set the extensonName key to an array of strings, not a single string with some commas in it.
Single machine:
Set-ADComputer -Identity test -Replace @{extensionName = "test.domain1.lab"', "Domain1.lab", "FQDN2.domain2.lab", "VIPName.lab"}

Open in new window

$DCController = (Get-ADDomainController -Filter *).Name
ForEach ($DC in $DCController) {
	Set-ADComputer -Identity $DC -Replace @{extensionName = "$($DC).domain1.lab"', "Domain1.lab", "FQDN2.domain2.lab", "VIPName.lab"}
}

Open in new window

JCJohnson76Author Commented:
Thank you for your input, but the syntax that you provided was incorrect though.  It also place me down the right path where I can help resolve this on my own.  
But again for your input; of helping to find my solution.  I have attached a file so you can see how I was able to resolve this issue.

I had to modify the string values with correct syntax.




$DCController = (Get-ADDomainController -Filter *).name

foreach($DC in $DCController){

Set-ADComputer -Identity $DC -Replace @{extensionName = $DC+"."+"domain1.lab," +,$DC+"." +"domain2,"+,"domain1.lab,vipname.lab"}

}





$DCController = (Get-ADDomainController -Filter *).Name

ForEach ($DC in $DCController)
{
      Set-ADComputer -Identity $DC -Replace @{extensionName = "$($DC).domain1.lab"', "Domain1.lab", "FQDN2.domain2.lab", "VIPName.lab"}
}
oBdACommented:
My PowerShell syntax was most definitely correct.
The strings created might not be what you expected, but it was not clear from your description where you wanted the DC name inserted; in your non-working example, it appeared only in one entry.
You said
I need to populate a multi-value strings
The "correct" command you posted,
Set-ADComputer -Identity $DC -Replace @{extensionName = $DC+"."+"domain1.lab," +,$DC+"." +"domain2,"+,"domain1.lab,vipname.lab"}
will not write multiple values into the extensionName array attribute, which is what your question indicated you wanted to do; It will write one single string (containing commas) into the first entry of the array.
In other words:
"FOO.domain1.lab,FOO.domain2,domain1.lab,vipname.lab"
instead of
"FOO.domain1.lab"
"FOO.domain2"
"domain1.lab"
"vipname.lab"

Is that really what you wanted to do?

And this is PowerShell, not VBS anymore, so there is no more need to "add" strings.
Depending on whether you really want one single string or an array, you can use
## Single string:
@{extensionName = "$($DC).domain1.lab,$($DC).domain2,domain1.lab,vipname.lab"}
## Array of strings:
@{extensionName = "$($DC).domain1.lab", "$($DC).domain2", "domain1.lab", "vipname.lab"}

Open in new window

Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

Michael B. SmithManaging ConsultantCommented:
:-)

Actually, you had an extra single quote in both your responses, rendering the syntax invalid.

"test.domain1.lab"'
"$($DC).domain1.lab"'
oBdACommented:
Eagle eye. I stand corrected, as far as the syntax is concerned. That's what happens when entering script in a non-monospaced font in a browser ...

Still like to know whether the single string is intentional ...
JCJohnson76Author Commented:
$DCController = (Get-ADDomainController -Filter *).name

foreach($DC in $DCController){

Set-ADComputer -Identity $DC -Replace @{extensionName = $DC+"."+"domain1.lab," +,$DC+"." +"domain2,"+,"domain1.lab,vipname.lab"}

}
JCJohnson76Author Commented:
$DCController = (Get-ADDomainController -Filter *).name

foreach($DC in $DCController){

Set-ADComputer -Identity $DC -Replace @{extensionName = $DC+"."+"domain1.lab," +,$DC+"." +"domain2,"+,"domain1.lab,vipname.lab"}

}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.