Get-MailboxStatistics with TotalItemSize in MB to a CSV file

Just ignore this, I wanted to store this code snippet somewhere and this was the best place.  But if you are interested this will create a csv file from Get-MailboxStatistics, but with the TotalItemSize in MB

“DisplayName,TotalItemSize(MB),ItemCount,StorageLimitSize,Database,LegacyDN” | out-file GMS.csv; get-mailbox -resultsize unlimited | Get-MailboxStatistics | ForEach{$a = $_.DisplayName;$b=$_.TotalItemSize.Value.ToMB();$c=$_.itemcount;$d=$_.storagelimitstatus;$e=$_.database;$f=$_.legacydn;”$a,$b,$c,$d,$e,$f”} | out-file GMS.csv -Append

Scheduling a Powershell Command

Just wanted to share this with you all.

So I have a number of scripts that I schedule to run either every 10 min, once a day or once a week.  It’s simple really, I create .cmd file that I then use the task scheduler or schtasks to create. 

Inside the .cmd file I have this:

powershell c:psTest-ExchangeServers.ps1 -localhost -testsmtp

That’s it .. well almost.  If the script needs to use any exchange commands, you need to add the exchange snap in.  To do that you need to add this to your .ps1 file.  The following command check to see if the snapin is loaded and if not it loads it.  That why  if you start the Exchange Management Shell it will no try to add the already loaded snapin

$xPsCheck = Get-PSSnapin | Select Name | Where {$_.Name -Like “*Exchange*”}; If ($xPsCheck -eq $Null) {Add-PsSnapin *Exchange*}

Enjoy

Exchange Powershell and Whatif

So I have been creating a few scripts to automate the configuration of exchange, and wanted to use the -WhatIf switch so you can see what would or would not change.

-WhatIf []
The WhatIf parameter instructs the command to simulate the actions that it would take on the object. By using the WhatIf parameter, you can vi ew what changes would occur without having to apply any of those changes. You don’t have to specify a value with the WhatIf parameter.

Now typically you would just use the -whatif switch after the command, but I just wanted one command and have the ability to turn on or off the switch, but keep the same line of code.

So I had a brain storm on the way in to work this morning and after a little try found out something (which If I have read the help listed above would have come quicker!)

So here we go, you can specify a $true or $false after the -WhatIf switch.  So what  you say, well you can pass that via a variable and that make things a whole lot more fun. so … the key here is the colon between -WhatIf and $True or $False

-WhatIf:$False

$xWhatIf = $true

Get-TransportServer LONINMEXD02  | Set-TransportServer -OutboundConnectionFailureRetryInterval 00:10:00 -WhatIf:$xWhatIf

What if: Setting transport server “loninmexd02.uk.db.com”.

** Value is not set **

$xWhatIf = $false

Get-TransportServer LONINMEXD02  | Set-TransportServer -OutboundConnectionFailureRetryInterval 00:10:00 -WhatIf:$xWhatIf

** Value IS set **

Sweet!