data _system_translations { ConvertFrom-StringData @' # Fallback text # Copy all the strings in the psd1 file here # Error chkAdldsError_title = AD LDS instance {0} service is not set to start automatically chkAdldsError_problem = AD LDS instance service is not set to start automatically for instance {0}. chkAdldsError_impact = AD LDS instance service is not set to start automatically for instance {0}. It will not be able to respond to client directory requests. chkAdldsError_resolution = Change service startup type to Automatic from Service Control Manager or run the following command in Windows Powershell window: Set-Service {0} -StartupType Automatic. chkAdldsPrecheck_title = AD LDS service is not configured chkAdldsPrecheck_problem = No AD LDS instances can be found. chkAdldsPrecheck_impact = Not applicable. chkAdldsPrecheck_resolution = Not applicable. chkAdldsInfo_title = AD LDS instance {0} service is set to start automatically chkAdldsInfo_compliant = AD LDS instance service is set to start automatically for instance {0}. '@ } Import-LocalizedData -BindingVariable _system_translations -fileName LightweightDirectoryServices.psd1 # # Synclet PowerShell Script for Scenario: AD BPA # Set-StrictMode -Version 2 # Target Namespace $tns = "http://schemas.microsoft.com/bestpractices/models/ServerManager/ADLDS/AdldsComposite/2008/04" ################################################################################################# # Output warning message for an error # $errVar should be of type System.Management.Automation.ErrorRecord # $errVar should NOT be $null ################################################################################################# function OutputError ($msg, $errVar) { $errMsg = @" $msg $errVar "@ Write-Warning $errMsg } function FormatBooleanText ($value) { if ($value) { "true" } else { "false" } } function CreateADLDSDocument ($ns) { $doc = [xml] "" [void] (DiscoverInstances $doc.DocumentElement $doc $ns) $doc } function DiscoverInstances ($parent, $doc, $ns) { $errVar = $null if (Test-Path HKLM:\System\CurrentControlSet\Services\DirectoryServices\Linkage) { $instances = Get-Item HKLM:\System\CurrentControlSet\Services\DirectoryServices\Linkage -ErrorVariable errVar if ($errVar) { [void] (OutputError "Cannot retrieve the AD LDS instance information. Make sure AD LDS instances are present." $errVar) } else { $instanceNames = $instances.GetValue("Export") foreach ($instanceName in $instanceNames) { $instanceData = Get-Item HKLM:\System\CurrentControlSet\Services\$instanceName -ErrorVariable errVar if ($errVar) { [void] (OutputError "Cannot retrieve the AD LDS instance service information. Make sure AD LDS instances are present." $errVar) } else { $instanceElement = $doc.CreateElement("Instance", $ns) $nameElement = $doc.CreateElement("Name", $ns) $nameElement.Set_InnerText($instanceData.GetValue("DisplayName")) $startElement = $doc.CreateElement("AutoStart", $ns) $startTypeAuto = $false if ($instanceData.GetValue("Start") -eq 2) { $startTypeAuto = $true } $autoStart = FormatBooleanText($startTypeAuto) $startElement.Set_InnerText($autoStart) $instanceElement.AppendChild($nameElement); $instanceElement.AppendChild($startElement); $parent.AppendChild($instanceElement); } } } } } ############################################################################## # Main entry point, start of calls to functions ############################################################################## # Instantiate the XML document to Output $doc = CreateADLDSDocument $tns # Saving output to a file for debugging purpose # Comment the following line before check-in #[void] $doc.Save("c:\temp\xmlout.xml") $doc