#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

Happy 10th Birthday Blog

Wow 10 years! .. Actually the first one was on the 6th June: Exchange 2003 Service Pack 1 – 06/06/2004 15:59:00 but I’m not sure what happened to that one :-|

So that makes this one! The one!

Service Pack 1 For Exchange 2003: 07/06/2004 10:17:00

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

Follow

Get every new post delivered to your Inbox.