FIM ScriptBox Item

Summary

The script code below uses Svrexport to determine a list of the last DCs used by your ADDS management agents.

Script Code

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
#---------------------------------------------------------------------------------------------------------------------------------
 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 
 } 
#---------------------------------------------------------------------------------------------------------------------------------

 

note Note
To provide feedback about this script, create a post on the FIM TechNet Forum.
For more FIM related Windows PowerShell scripts, see the FIM ScriptBox.

 



See Also