Find Exchange Databases using Powershell

A small change in $strFilter=”(objectClass=msExchPrivateMDB)” and you get all the mailbox databases ;-)

$forest    = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Dom  = "LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=" + $Forest.Name.Replace(".",",DC=")
$strFilter="(objectClass=msExchPrivateMDB)"
$Root       = New-Object DirectoryServices.DirectoryEntry $Dom 
$selector   = New-Object DirectoryServices.DirectorySearcher 
$selector.PageSize    = 1000 
$selector.Filter      = $strFilter 
$selector.SearchRoot  = $root 
$selector.SearchScope = "Subtree" 
$Objs = $selector.findall() 
$Objs.count 
$Objs 

Find Exchange Servers using Powershell

#Powershell #MsExchange

I have a suite of discovery scripts that I use every now and then.  I adapted this to look in the AD and get a list of the exchange servers!

$forest    = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Dom = "LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=" + $Forest.Name.Replace(".",",DC=")
$strFilter="(objectClass=msExchExchangeServer)"
$Root       = New-Object DirectoryServices.DirectoryEntry $Dom
$selector   = New-Object DirectoryServices.DirectorySearcher
$selector.PageSize   = 1000
$selector.Filter     = $strFilter
$selector.SearchRoot = $root
$selector.SearchScope = "Subtree"
$Objs = $selector.findall()
$Objs.count
$Objs

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

Follow

Get every new post delivered to your Inbox.