Working with SharePoint and DSC - Generating the MOF files and letting it all just happen
**UPDATE: I have modified the script and provided better how to steps, follow these links How to... and Script download please keep reading on to understand how the script DSC_Generate_MOFFiles.ps1 works
We are basically done, DSC is configured and running on our Nodes as well as the Pull server all we have to do is generate the instructions and watch our farm get built.Â But first as a recap this is what we have done
In this script we perform the following steps:
- Collect Service account passwords (Never hardcode them)
- Create MOF Files for nodes to pull and apply
Looking at the script the first section of interest is where we collect the usernames for our service accounts, then we prompt you for the passwords and we get the passphrase for the farm which we hash and store in variables.
NOTE: I suggest you write your passwords in a text file and copy them in to insure you have the correct passwords.
$setupAccountName = $data.NonNodeData.SharePoint.ServiceAccounts.SetupAccount
$farmAccountName = $data.NonNodeData.SharePoint.ServiceAccounts.FarmAccount
$webAppAccountName = $data.NonNodeData.SharePoint.ServiceAccounts.WebAppPoolAccount
$svcAppAccountName = $data.NonNodeData.SharePoint.ServiceAccounts.ServicesAppPoolAccount
$srcContentAccessAccount = $data.NonNodeData.SharePoint.ServiceAccounts.ContentAccessAccount
$ConnectAccounts = $data.NonNodeData.SharePoint.ServiceAccounts.ConnectionAccount
Write-Host "Getting Service Account Credentials" -ForegroundColor Green
$SetupAccount = Get-Credential -UserName $setupAccountName -Message "Setup Account"
$FarmAccount = Get-CredentialÂ -UserName $farmAccountName -Message "Farm Account"
$WebAppPoolAccount = Get-Credential -UserName $webAppAccountName -Message "Web App Pool Account"
$ServicePoolAccount = Get-Credential -UserName $svcAppAccountName -Message "Svc App Pool Account"
$ContentAccessAccount = Get-Credential -UserName $srcContentAccessAccount -Message "Search Default Content Access Account"
$passPhrase = Get-Credential -Message "Farm PassPhrase" -UserName "PassPhrase"
Next we create the instructions (MOF files) and there checksum files
Write-Host "Generating DSC Configuration into " $dscConfigPath -ForegroundColor Green
SharePointServer -FarmAccount $FarmAccount -WebPoolManagedAccount $WebAppPoolAccount -SPSetupAccount $SetupAccount -ServicePoolManagedAccount $ServicePoolAccount `
-ContentAccessAccount $ContentAccessAccount -outputpath $dscConfigPath -ConfigurationData $ConfigData -UPASyncConnectAccounts $ConnectAccount -PassPhrase $passPhrase
Write-Host "Creating checksums for all MOF..." -ForegroundColor Green
New-DSCCheckSum -Path $dscConfigPath -Force
And that's it, really a simple script. You can run this script as often as you want, so as you make changes to the Config and Configdata files you can push the changes out with this file.
Now just sit back and watch your servers install SharePoint exactly the way you want it to.
NOTE: This can take several hours and really is like watching paint dry so I suggest you grab a coffee and go do other work.
You can find a copy of my script here
P.S. I have commented out a few sections as I'm not using them but left them in because future iterations might, if you think you want to use them then have fun.