Dynamic domain in script

Jun 16, 2011 at 12:58 PM
Edited Jun 16, 2011 at 12:58 PM

Hey!

We use the script in many different domains, and have a standard XML configuration file we use.

But every now and then we forgot to change the domain in the XML file, and everything would fail! - hmmm.

So we made one very small addition to the AutoSPInstallerMain.ps1 file:

Instead of:
##$xmlinput = [xml] (get-content $InputFile)
# Globally update all instances of "localhost" in the input file to actual local server name
[xml]$xmlinput = (Get-Content $InputFile) -replace ("localhost", $env:COMPUTERNAME)

we use:
##$xmlinput = [xml] (get-content $InputFile)
# Globally update all instances of "localhost" in the input file to actual local server name + all instances of %DOMAIN% to current domain
[xml]$xmlinput = ((Get-Content $InputFile) -replace ("localhost", $env:COMPUTERNAME)) -replace ("%DOMAIN%", $env:USERDOMAIN)

So now we can use:

------------------- snip ---------------------

        <Account AddToLocalAdminsDuringSetup="False">
            <Username>%DOMAIN%\SharePointServiceAccountName</Username>
            <Password>TotallySecret</Password>
            <Email>sp2010@domain.com</Email>
        </Account>

---------------------------------------------

and we can use this in every domain we transfer across (we use different domains for different stages: dev, test, prod) with having to remember to change the domain part of usernames :-)

Hope some of you can use this :-)

Cheers
Jesper

Coordinator
Jun 17, 2011 at 12:12 PM

Thanks Jesper, I considered doing something like this a while ago but couldn't assume that the current logon domain $env:USERDOMAIN would be the same as the domain in which the service accounts existed. However your way makes it more explicit so I'll have another look!

Brian

Coordinator
Jun 17, 2011 at 12:13 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.