Troubleshooting through comparison


Ever run into an issue where one user or server works but another doesn’t and you wonder “what’s different”? Powershell to the rescue!! using compare-object and get content against the output of a get- command.

I am working on a script that all you have to do is answer the questions, and another to pull all the pertinent data for an environment and provide a comparison.

But for now here are some examples to get you started:

Compare user settings

  • get-casmailbox UserA| fl > c:\a.txt
  • get-casmailbox userB| fl > c:\b.txt
  • or
  • get-mailbox UserA| fl > c:\a.txt
  • get-mailbox userB| fl > c:\b.txt

Compare CAS server settings

  • get-ClientAccessServer ServerA | fl > c:\a.txt
  • get-ClientAccessServer ServerB | fl > c:\b.txt

Compare Exchange Servers

get-EXchangeServer ServerA | fl > c:\a.txt
get-EXchangeServer ServerB | fl > c:\b.txt

Run

Compare-Object $(Get-Content c:\a.txt) $(Get-Content c:\b.txt) -includeequal

 

Here is the draft of the script, you will notice that there are several slots open for additional comparison please let me know if you would like me to add something to it or if you have any issues.

EDIT – I have added Service state and fixed 2 bugs I found in the script.

****************Start Of Script***************************************************

CLS
write-host
write-host
write-host Script provided by http://ExchangeMaster.wordpress.com -ForegroundColor green
write-host Exchange Server 2010\2007 – comparison script
write-host Please, select which comparison you are going to run..
write-host
write-host ’1) Compare Exchange servers’
write-host ’2) Compare 2010 CAS servers’
write-host ’3) Compare Mailbox servers’
write-host ’4) Compare Transport servers’
write-host ’5) Compare 2007 CAS servers’
write-host ’6) Compare Mail Enabled users’
write-host ’7) Compare Service State’
write-host ’8) ’
write-host ’9) ’
write-host ’10)’
write-host
write-host “Select an option.. [1-10]? “
$opt = read-host

switch ($opt)
    {
        1 { $serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    get-exchangeserver $ServerA | fl >  $env:temp\$ServerA.txt        
    get-exchangeserver $ServerB | fl >  $env:temp\$serverb.txt
    Get-Service -ComputerName $ServerA |Ft  name, status -a >>  $env:temp\$ServerA.txt
    Get-Service -ComputerName $ServerB |Ft  name, status -a >>  $env:temp\$serverb.txt
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_2010_EXchange.txt
    Invoke-Item $env:temp\Compare_2010_Exchange.txt}

        2 { $serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    Get-ClientAccessServer $ServerA | fl >  $env:temp\$ServerA.txt
    Get-OwaVirtualDirectory -Identity $servera\* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$ServerA.txt
    Get-ecpVirtualDirectory -Identity $servera\* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$ServerA.txt   
    Get-webservicesVirtualDirectory -Identity $servera\* | fl server, name, internalurl, externalurl >> $env:temp\$ServerA.txt
    Get-oabVirtualDirectory -Identity $servera\* | fl server, name, internalurl, externalurl >> $env:temp\$servera.txt
    Get-ClientAccessServer $Serverb | fl >  $env:temp\$ServerB.txt
    Get-OwaVirtualDirectory -Identity $serverb\* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$serverb.txt
    Get-ecpVirtualDirectory -Identity $serverb\* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$serverb.txt
    Get-webservicesVirtualDirectory -Identity $serverb\* | fl server, name, internalurl, externalurl >> $env:temp\$serverb.txt
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_2010_Cas.txt
    Invoke-Item $env:temp\Compare_2010_Cas.txt}

        3 { $serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    get-mailboxServer $ServerA | fl >  $env:temp\$servera.txt
    get-mailboxServer $ServerB | fl >  $env:temp\$ServerB.txt
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_2010_MAilbox.txt
    Invoke-Item $env:temp\Compare_2010_mailbox.txt}

        4 {$serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    get-TRansportServer $ServerA | fl >  $env:temp\$servera.txt
    get-transportServer $ServerB | fl >  $env:temp\$ServerB.txt
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_2010_Transport.txt
    Invoke-Item $env:temp\Compare_2010_Transport.txt}

        5 { $serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    Get-ClientAccessServer $ServerA | fl >  $env:temp\$ServerA.txt
    Get-OwaVirtualDirectory -Identity $servera\owa* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$ServerA.txt
    Get-webservicesVirtualDirectory -Identity $servera\* | fl server, name, internalurl, externalurl >> $env:temp\$ServerA.txt
    Get-oabVirtualDirectory -Identity $servera\* | fl server, name, internalurl, externalurl >> $env:temp\$servera.txt
    Get-ClientAccessServer $Serverb | fl >  $env:temp\$ServerB.txt
    Get-OwaVirtualDirectory -Identity $serverb\owa* | fl name, server, *url*, *auth*, *enabled, *version >> $env:temp\$serverb.txt
    Get-webservicesVirtualDirectory -Identity $serverb\* | fl server, name, internalurl, externalurl >> $env:temp\$serverb.txt
    Get-oabVirtualDirectory -Identity $serverb\* | fl server, name, internalurl, externalurl >> $env:temp\$serverb.txt   
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_2007_Cas.txt
    Invoke-Item $env:temp\Compare_2007_Cas.txt}

        6 { $userA = read-host "Enter the name of the First user"
    $userB = read-host "Enter the name of the second user"
    get-mailbox $userA | fl >  $env:temp\$usera.txt
    get-casmailbox $userA | fl >>  $env:temp\$usera.txt
    get-Mailboxpermission $userA | fl >>  $env:temp\$usera.txt
    get-mailbox $userB | fl >  $env:temp\$UserB.txt
    get-casmailbox $userB | fl >>  $env:temp\$UserB.txt
    get-Mailboxpermission $userB | fl >>  $env:temp\$USerB.txt
    Compare-Object $(Get-Content  $env:temp\$userA.txt) $(Get-Content  $env:temp\$userb.txt) -includeequal > $env:temp\Compare_user.txt
    Invoke-Item $env:temp\Compare_user.txt}

        7 { $serverA = read-host "Enter the name of the fisrt server"
    $ServerB = read-host "Enter the name of the second server"
    Get-Service -ComputerName $ServerA |Ft  name, status -a >  $env:temp\$ServerA.txt
    Get-Service -ComputerName $ServerB |Ft  name, status -a >  $env:temp\$serverb.txt
    Compare-Object $(Get-Content  $env:temp\$ServerA.txt) $(Get-Content  $env:temp\$serverb.txt) -includeequal > $env:temp\Compare_SErvices.txt
    Invoke-Item $env:temp\Compare_SErvices.txt}
    8 { }
        9 { }
        10 { }
        default {write-host “You haven’t selected any of the available options. “}
    }

*****************End of Script***********************************************************

One thought on “Troubleshooting through comparison

  1. Howdy! I simply want to give you a big thumbs up for your great information you’ve got right here on this post. I’ll be coming back to your blog for more soon.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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