Backing up Exchange Server 2010 with Windows Server Backup and Powershell

#powershell #msexchange

This was fun, or not as the case may be.So I have a temporary Exchange 2010 server that I am using to migrate users on to, and then off at a later date.

I slapped a 2TB external usb disk in the back of the server and wanted to back it up.  Using the GUI is easy, but I wanted to use Powershell do it!

Now you can use wbadmin to run a backup, but this for some reason doesn’t work if you run it in powershell.  After some digging I found the powershell snapin windows.serverbackup

So you can start powershell and run Add-PsSnapin windows.serverbackup

You then find a whole load of cmdlets you can use.  Check it them here: http://technet.microsoft.com/en-us/library/ee706683.aspx<

I’m not going to go in to real detail, but this is basics:

$policy = New-WBPolicy
$fileSpec = New-WBFileSpec -FileSpec D:\exchange.databases\database.swing01 
Add-WBFileSpec -Policy $policy -FileSpec $filespec
$fileSpec = New-WBFileSpec -FileSpec D:\exchange.databases\database.swing02 
Add-WBFileSpec -Policy $policy -FileSpec $filespec
$fileSpec = New-WBFileSpec -FileSpec D:\exchange.databases\database.swing03 
Add-WBFileSpec -Policy $policy -FileSpec $filespec

Set-WBVssBackupOptions -Policy $policy -VssFullBackup   
$backupLocation = New-WBBackupTarget -NetworkPath $BackupTarget 
Add-WBBackupTarget -Policy $policy -Target $backupLocation   
Start-WBBackup -Policy $policy

Microsoft Surface Pro 3

#SurfacePro3 #Surface

 

Well, well, well, I can confirm that the Surface Pro 3 does actually exist.  In the UK mine rocked up on Thursday 28th August 2014 as anticipated. WP_20140828_14_56_05_Pro
When you open the box you have the tablet WP_20140828_15_46_16_Pro
Under it the is the pen, the user guide and the power supply.You have to put the battery in the pen, and the power supply does have a USB port on it too, which is good. WP_20140828_15_46_46_Pro

Now the surface pro as been to the phat farm! The original Surface RT comes in at 689g, while the Surface Pro tips the scales at 913g (My Lenovo Helix is 851g). The Surface Pro 3 is only 804g! and a lot bigger.

As a comparison, this is the Surface Pro vs Surface Rt WP_20140828_15_45_03_Pro

While the Surface Pro vs Surface Pro 3.  So for people in the UK, the Surface Pro 3 is about the size of a sheet a A4 paper. WP_20140828_15_51_21_Pro

To top it off you can see how much thinner the Surface Pro 3 is to a Surface Pro (on the right) WP_20140828_15_55_02_Pro
Now for the keyboards!  Shame Microsoft doesn’t bundle them in with the surface.  The surface Pro 3 is larger than the Surface Pro, so the keyboard are bigger WP_20140828_15_43_37_Pro
What is kinda cool is that the keyboard lights up up ;-) WP_20140829_22_44_14_Pro
Right, let get down to it then. So I have the core i7 version and it quite nippy as you would expect. It has 512GB SSD and 8GB of RAM. sp3_cpuz1

sp3_cpuz2

The screen is very nice sp3_display

sp3_cpuz3

I have only been using my Surface Pro 3 since Thursday, and have not had the chance to really using it in anger.  However, I have performed a really basic battery test.From fully charged (The manual says it takes 2-4 hours to fully charge your Surface Pro 3 battery from an empty state),  I have watched 4x50min episodes of a TV series from an external hard disk.After the first one the battery went from 100% to 85% and the last 3 used ~ 20% of battery each leaving me with 10% and a low battery warning.For me this ok!  I don’t have anything else to compare it against but I can live with that.  So on Monday, I used my Surface Pro 3 “normally” on WiFi, VPN’ed to work, using an RDP session, PowerPoint, word and a bit of windows powershell. End result was around 6 hours use.  I feel that is acceptable.Oh by the way, the video play back was awesome and the audio was good too!
This is taken from the surface pro 3 user guide http://www.microsoft.com/surface/en-us/support/userguides with some comments.Touchscreen: The 12” touchscreen, with its 3:2 aspect ratio and 2160 x 1440 resolution display. Multi-touch lets you use your fingers to select, zoom, and move things around.Surface Pen: Enjoy a natural writing experience, with a pen that feels like an actual pen. [It actually does feel really nice and has a good weight to it too!]

Kickstand: Flip out the Surface Pro 3 kickstand to any angle and work or play comfortably at your desk, .on the couch, or while giving a hands-free presentation. Choose the angle that’s right for you. [This is really strange.  If flips out to one angle, but then you need to move it to adjust it more.  At first it feels like your going to break it!]

Wi-Fi and Bluetooth: Surface supports standard Wi-Fi protocols (802.11a/b/g/n/ac) and Bluetooth® 4.0 Low Energy technology.

Two cameras and two microphones: Two 5-megapixel cameras for recording videos and taking pictures. Both cameras record video in 1080p, with a 16:9 aspect ratio (widescreen).

Stereo speakers and headset jack: Stereo speakers with Dolby® enhanced sound and headset jack.

Full-size USB 3.0 port: Connect USB accessories—like a mouse, printer, or an Ethernet adapter.

microSD card reader: Use the microSD card reader [This is what my Lenovo Helix is missing!].

Mini DisplayPort 1.2: Share what’s on your Surface Pro 3 by connecting it to an HDTV, monitor, or projector.

Charging port and 36-watt power supply: Connect the included 36-watt power supply when your battery is low [Has a USB port in it too!].

Processor: 4th generation Intel® Core™ i3, i5, i7

Storage and Memory: Choose from 64GB or 128GB storage with 4GB RAM, or 256GB or 512GB storage with 8GB RAM.

TPM: TPM chip [Now this is interesting, by default the C drive is bitlocker encrypted!].

Sensors: Surface has four sensors (an ambient light sensor, an accelerometer, gyroscope, and magnetometer).

Surface-Pro-3Surface-Pro-3-Back

So, what do I think? Well I have used a lot of tablets over the years.  It started with a Toshiba M400 and my last one was a Lenovo Helix.  The Microsoft Surface Pro 3 is by far the best I have used. Size, weight and usability are excellent, the only thing that lets it down is the price, and with I mean the extra cost for the keyboard. If it wanted anything else, I would say another usb3 and maybe 3g, but that is all.

But so far I love it!

#Powershell Export-Clixml and Import-Clixml

I had a need to store some user data.  Using the Exchange 2010 Management Shell I could use Get-User and Get-Mailbox to get what I needed, but when you export it to CSV, some of the fields don’t export very well at all.I was looking at all kinds of funky ways to export the data, but then stumbled upon Export-Clixml.

I was amazed.  I could run say Get-Mailbox bob | Export-Cixml bob.xml

Then I could run $x = Import-Clixml bob.xml anywhere and I would have a variable ($x) with bob’s mailbox information in!

How cool is that!

#NetApp DataOnTap and Invoke-NaSysstat

So I have been play with the NetApp DataOnTap add in for a while now want to share this.  Essentially all it does is run Invoke-NaSysstat at timed intervals and saves it to an hourly csv file

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$filer   = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the comma seperated filer name", "Enter Filer Name", "")

#Change to match you path
Import-Module E:\PsMON\netapp\DataONTAP.psd1
Connect-NaController $Filer -Credential root

$matrix = @()
$doit = $True

$timer = 10

$LastHour = (Get-Date -format "HH")

while($doit){
  $ThisHour = (Get-Date -format "HH")
  $tSysStat = Invoke-NaSysstat -Count 1 | Select
  $tSysStat
  $matrix += $tSysStat
  If($ThisHour -ne $LastHour){
    $outFile = $filer + "_" + (Get-Date -format "yyyy-MM-dd_HHmm") + ".csv";
    $Matrix | Export-Csv $outFile -NoTypeInformation;$matrix = @();
    "-$outFile-"
  }
  $LastHour = $ThisHour

  For($i=0;$i-le $timer;$i++){Sleep 1 }
}

$outFile = $filer + "_" + (Get-Date -format "yyyy-MM-dd_HHmm") + ".csv";$Matrix | Export-Csv $outFile -NoTypeInformation

Exchange Server 2010 Group Usage with Windows Powershell

#MsExchange #IAMMEC

So I have been running some discovery scripts on an M&A and wanted to check DL’s and when they were last used.  Came up with this ..

$days = 90
Set-ADServerSettings -ViewEntireForest:$true
$results = Get-TransportServer | get-messagetrackinglog -eventid expand -resultsize unlimited -start (get-date).addDays(-$days) | sort timestamp -desc
$results.count

IF(![string]::IsNullOrEmpty($results)) {
  $report = @()
  $lists = @()
  $data = $results | group relatedrecipientaddress | sort name
  $lists = get-distributiongroup -resultsize unlimited | Select Alias, primarysmtpaddress, Name, RecipientType, OrganizationalUnit, @{Expression={""};Label="Count"}, @{Expression={""};Label="LastUsed"}
  $lists += Get-DynamicDistributionGroup -ResultSize unlimited | Select Alias, primarysmtpaddress, Name, RecipientType, OrganizationalUnit, @{Expression={""};Label="Count"}, @{Expression={""};Label="LastUsed"}
  $lists = $lists | sort alias
  foreach ($list in $lists) {
    $check = $null
    $check = $data | ?{$_.name -like "$($list.primarySMTPaddress.tostring())"}
    if ($check) {
      $List.Count = $Check.Count
      $List.LastUsed = ($check | select -expand group | select -first 1).TimeStamp
    }
  }
}

$lists | Export-csv GroupsWithUsage.csv -NoTypeInformation -Encoding  Unicode

Enjoy

NetApp SnapManager for Exchange and The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

#NetApp #MsExchange

Okay so nailed this one eventually.

[SERVER1] Initializing SnapManager server on remote machine [SERVER2]…
[SERVER1] Connecting to remote server [SERVER2]…
[SERVER1] Remote server [SERVER2] is connected successfully.
[SERVER1] Verify Sme Launch Exception, Error code: 0x80131501, Error description: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state., stack trace:
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfFaulted()
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMes
[21:02:47.831]  [SERVER1] Verify SME Launch on SERVER2 returned error 0x80131501
[SERVER1] Verify Sme Launch2 Exception, Error code: 0x80131501 [The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.], stack trace:
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IM
[SERVER1] CCR/DAG Remote Rename Backup Exception, Error code: 0x80131501 [The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.], stack trace:
Server stack trace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturn

[SERVER1] Error Code: 0x80131501
Please check the SnapManager-SnapDrive Reports and Windows Event Logs for more details.

It was caused by the Cisco ASA firewall on our Inter DC link timing out idle connections after one hour.

When the SME service starts, it establishes a connection over TCP port 810 to other servers in it’s DAG. SME expects the link to be available all the time and not time out.

SME is a but stupid, in that as it EXPECTS the link to be open, and s.

Workaround: Restart the SnapManagerService before the Backups Starts.
Solution#1: Increase the timeout value on the ASA firewalls for port 808 and 810 from 1 hour to8 hours  (we do backups every 6 hours).
Solution#2: Product change to SME, so before it initiates a backup, it actually re-establishes the connection before it starts. BUG/RFE 828920 has been raised to address this.

 

 

NetApp SnapManager for Exchange and Asynchronous call DoSnapshotSet timed out! errors

#NetApp #MsExchange

Have some issues with SME backing up Exchange and it throwing “Asynchronous call DoSnapshotSet timed out!” all over the backup log.

Well it appears that having free_space_realloc=on set on the Aggregates caused this.  As soon as it was set to off, this issue went away.

That just leaves this error to be fixed

Verify Sme Launch Exception, Error code: 0x80131501, Error description: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

 

#MsExchange 2010 Get-MailboxDatabaseCopyStatus

So Tony Redmond gave me a blank look when I spoke to him for like 30 seconds at MEC, but this little code snippet is featured on PG 491 of Microsoft Exchange 2010 Inside Out.

I use this a lot, and have it wrapped in to a .ps1. Just discovered that like Get-ExchangeServer you can pipe an array of objects to Get-MailboxDatabase. So you could say run:

"db01","db02" | Get-MailboxDatabase
Now that is cool. I have an issue at the moment where some Donkey thought it would be a good idea to reseed two 600GB databases (We use NetApp storage so there is a better way to do it!). I wanted a way to keep an eye on them so I updated the original script.

Do you can use the -database switch like this to get the database copy status for db01 and db04
 .\Check-DatabaseCopyStatus.ps1 -Database @("db01","db04")

-and you could you the server switch to get the database copy status for db01 and db04 just on ex1
 .\Check-DatabaseCopyStatus.ps1 -Database @("db01","db04") -Server ex1

Enjoy
PARAM([String]$Server="", [String[]]$Database = "*")
If($server -ne ""){$srvtxt=$server;$Server="\" + $server.ToUpper()}ELSE{$srvTxt="All"}
Write-Host "Server:" $srvtxt "`nDatabase:"$Database "`n"

##########################################################################################
#Load the Exchange 2010 bits & bobs
#########################################################################################
$xPsCheck = Get-PSSnapin | Select Name | Where {$_.Name -Like "*Exchange*"}
If ($xPsCheck -eq $Null) {Write-Host "Loading Exchange Snapin"; Add-PsSnapin Microsoft.Exchange.Management.PowerShell.e2010}

$Database | Get-MailboxDatabase | Sort Name | FOREACH {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference| Where {$_.Value -eq 1}; Write-Host $db "on" $xNow "Should be on" $dbOwn.Key -NoNewLine; If ( $xNow -ne $dbOwn.Key){Write-host " WRONG" -ForegroundColor Red; }ELSE{Write-Host " OK" -Foregroundcolor Green};Get-MailboxDatabaseCopyStatus $db$Server;"`n"}

Download it from here

#Powershell and #NetApp SnapDrive

I blogged this script earlier, but discovered an undocumented feature where the last entry in the output was not added to the array object.  Here is the updated version

Write-Host "Running sdcli disk list"
$diskInfo = Invoke-Expression "sdcli disk list"
$sdclidisks  = @()

$fields  = "UNCPath","LUNPath","StorageSystem","StorageSystemPath","Type","Diskserialnumber","BackedbySnapshotCopy"
$fields += "Shared","BootOrSystemDisk","SCSIport","Bus","Target","LUN","Readonly","Size","SnapmirrorSource","SnapvaultPrimary"
$fields += "DiskPartitionStyle","CloneSplitRestorestatus","DiskID","VolumeName","Mountpoints","IPAddresses","FCinitiatorWWPN"
ForEach($Item in $DiskInfo){
  $tmpItem = $Item.Trim()
  $tmpItemSplit = $tmpItem.Split(":")
  Switch -Wildcard ($tmpItem){
    "The operation completed successfully.*" {$sdclidisks  += $sdcliDiskList}
    "UNC Path:*"  {$sdclidisks  += $sdcliDiskList
                   $sdcliDiskList = "" | Select $fields
                   $sdcliDiskList.UNCPath = $tmpItemSplit[-1]}

    "LUN Path:*"                   {$sdcliDiskList.LUNPath                 = $tmpItemSplit[-1]}
    "Storage System:*"             {$sdcliDiskList.StorageSystem           = $tmpItemSplit[-1].trim()}
    "Storage System Path:*"        {$sdcliDiskList.StorageSystemPath       = $tmpItemSplit[-1].trim()}
    "Type:*"                       {$sdcliDiskList.Type                    = $tmpItemSplit[-1].trim()}
    "Disk serial number:*"         {$sdcliDiskList.Diskserialnumber        = $tmpItemSplit[-1].trim()}
    "Backed by Snapshot Copy:*"    {$sdcliDiskList.BackedbySnapshotCopy    = $tmpItemSplit[-1].trim()}
    "Shared:*"                     {$sdcliDiskList.Shared                  = $tmpItemSplit[-1].trim()}
    "BootOrSystem Disk:*"          {$sdcliDiskList.BootOrSystemDisk        = $tmpItemSplit[-1].trim()}
    "SCSI port:*"                  {$sdcliDiskList.SCSIport                = $tmpItemSplit[-1].trim()}
    "Bus:*"                        {$sdcliDiskList.Bus                     = $tmpItemSplit[-1].trim()}
    "Target:*"                     {$sdcliDiskList.Target                  = $tmpItemSplit[-1].trim()}
    "LUN:*"                        {$sdcliDiskList.Lun                     = $tmpItemSplit[-1].trim()}
    "Readonly:*"                   {$sdcliDiskList.Readonly                = $tmpItemSplit[-1].trim()}
    "Size:*"                       {$sdcliDiskList.Size                    = $tmpItemSplit[-1].trim()}
    "Snapmirror Source:*"          {$sdcliDiskList.SnapmirrorSource        = $tmpItemSplit[-1].trim()}
    "Snapvault Primary:*"          {$sdcliDiskList.SnapvaultPrimary        = $tmpItemSplit[-1].trim()}
    "Disk Partition Style:*"       {$sdcliDiskList.DiskPartitionStyle      = $tmpItemSplit[-1].trim()}
    "Clone Split Restore status:*" {$sdcliDiskList.CloneSplitRestorestatus = $tmpItemSplit[-1].trim()}
    "DiskID:*"                     {$sdcliDiskList.DiskID                  = $tmpItemSplit[-1].trim()}
    "Volume Name:*"                {$sdcliDiskList.VolumeName              = $tmpItemSplit[-1].trim()}
    "*Mount points:*"              {$sdcliDiskList.Mountpoints             = $tmpItem.Split("`t")[-1].trim()}
    "IP Addresses:*"               {$sdcliDiskList.IPAddresses             = $tmpItemSplit[-1].trim()}
   "FC initiator WWPN:*"           {$sdcliDiskList.FCinitiatorWWPN         = $tmpItem.Split("`t")[-1].trim()}
  }
 }

$sdclidisks = $sdclidisks | where {$_.DiskID -ne $Null}

Now you have $sdclidisks you can say export to csv.

Download

Enjoy