Get a List of InSite DCs from Eventlog

#MsExchange #Powershell

So I have been having a bit of fun (well not really). The company I am working for has multiple AD domains in a single forest and the users are spread over the domains.

To start with, with almost every Exchange Management Shell cmdlet I run I need to also run the following:

Set-AdServerSettings -ViewEntireForest $True

Now with mailbox move requests, the exchange servers are in one domain and the users in another. I wanted a way to take the output from the MSExchange ADAccess 2080 event in the application event log and generate an array I can then play with in a script. I then use the array to use the right DC with the -DomainController switch. I came up with this:

$Evt2080 = Get-EventLog Application -Source “MSExchange ADAccess” | where {($_.Category -eq “Topology”) -AND ($_.EventId -eq 2080)} | Select -first 1

$InSiteMatrix = @()
$Fields = “Server”, “Roles”, “Enabled”, “Reachability”, “Synchronized”, “GCcapable”, “PDC”, “SACLright”, “CriticalData”, “Netlogon”, “OSVersion”
$InSite = ($Evt2080.ReplacementStrings[-2]).Split(“`n”) | Where {$_}
ForEach($Item in $InSite){
$tmpMatrix = “” | Select $Fields
$tmpSplit = $item.Split(“`t”)
$tmpMatrix.Server = $tmpSplit[0]
If($tmpMatrix.Server -ne “”){
$tmpValues = $tmpSplit[-1].split(” “)
ForEach($thing in $tmpValues ){
$tmpMatrix.($Fields[$i]) = $thing
$InSiteMatrix += $tmpMatrix



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: