Using PowerShell to determine a list of the last DCs used by your AD management agents
Summary The script code below uses Svrexport to determine a list of the last DCs used by your AD management agents. #--------------------------------------------------------------------------------------------------------------------------------- Set-Variable -name REGKEY -value "HKLM:\SYSTEM\CurrentControlSet\Services\FIMSynchronizationService\Parameters" -option constant#--------------------------------------------------------------------------------------------------------------------------------- Function GetDcObject { Param($maName, $partName, $dcName) End { $newRecord = new-object psobject $newRecord | add-member noteproperty "MA-Name" $maName $newRecord | add-member noteproperty "Partition" $partName $newRecord | add-member noteproperty "DC-Name" $dcName return $newRecord } }#--------------------------------------------------------------------------------------------------------------------------------- #Clear-Host If(@(Get-PSSnapin | Where-Object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {Add-PSSnapin FIMAutomation} $curFolder = Split-Path -Parent $MyInvocation.MyCommand.Path $dataFolder = "$curFolder\Data" If(Test-Path $dataFolder) {Remove-Item $dataFolder -Recurse -Force} New-Item $dataFolder -type directory | Out-Null $regValue = get-itemproperty -name Path -path $REGKEY $toolPath = "$($RegValue.Path)Bin\svrexport.exe" Write-Host "Processing SrvExport - please wait..." $startinfo = new-object diagnostics.processstartinfo $startinfo.filename = $toolPath $startinfo.arguments = $dataFolder $startinfo.UseShellExecute = $false $startinfo.CreateNoWindow = $true $process=[Diagnostics.Process]::Start($startinfo) $process.WaitForExit() If($process.ExitCode -ne 0) {Throw "Failed to run srvexport"}#--------------------------------------------------------------------------------------------------------------------------------- $dataList = @() $dataList.length Get-ChildItem $dataFolder -Filter "*.xml" | ForEach { If($_.Name.toLower().StartsWith("mv") -eq $false) { [Xml]$xmlDoc = get-content "$dataFolder\$($_.Name)" $catNode = $xmlDoc.selectSingleNode("saved-ma-configuration/ma-data/category") If(($catNode -ne $null) -band ($catNode.get_InnerText() -eq "AD")) { ForEach($dcNode In $xmlDoc.selectNodes("//last-dc")) { $maNode = $dcNode.get_parentNode().get_parentNode().get_parentNode().get_parentNode().get_parentNode() $dataList += GetDcObject -maName $maNode.name ` -partName $dcNode.get_parentNode().selectSingleNode("dn").get_InnerText() ` -dcName $dcNode.get_InnerText() } } } }#--------------------------------------------------------------------------------------------------------------------------------- Clear-Host If($dataList.length -eq 0) {Write-Host "No DCs found"} Else { Write-Host "Domain Controller List" Write-Host "======================" $dataList | Format-List } #---------------------------------------------------------------------------------------------------------------------------------v Go to the FIM ScriptBox Markus Vilcinskas, Knowledge Engineer, Microsoft Corporation
May 10th, 2010 5:02am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics