Automated Extensionname for each domain controllers

JCJohnson76
JCJohnson76 used Ask the Experts™
on
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 :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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

Author

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"}
}
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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 you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Michael B. SmithManaging Consultant

Commented:
:-)

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

"test.domain1.lab"'
"$($DC).domain1.lab"'
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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 ...

Author

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"}

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

foreach($DC in $DCController){

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

}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial