All posts by Sysop

Removing Exchange 2010

This assumes that you are removing the LAST Exchange 2010 Server in a domain after moving to Office 365…

DISABLE the Mailboxes, be careful the other option bins the AD user object as well!!

Delete all User Public folders:
$ExchangeServer = "ServerName"
Get-PublicFolder -Server $ExchangeServer "\" -Recurse -ResultSize:Unlimited | Remove-PublicFolder -Server $ExchangeServer -Recurse -ErrorAction:SilentlyContinue

Delete all System Public folders:
Get-PublicFolder -Server $ExchangeServer "\Non_Ipm_Subtree" -Recurse -ResultSize:Unlimited | Remove-PublicFolder -Server $ExchangeServer -Recurse -ErrorAction:SilentlyContinue

Delete the Default Offline Address Book.

Delete the Mailbox Databases

Check if a specific mailbox database that you cannot remove through EMC contains a mailbox and what type they are:
get-mailbox -database "Mailbox Database"
get-mailbox -database "Mailbox Database" -archive
get-mailbox -database "Mailbox Database" -arbitration

Assuming that there are arbitration mailboxes, this is how you remove them:
get-mailbox -database "Mailbox Database" -arbitration | disable-mailbox -arbitration -disablelastarbitrationmailboxallowed

Remove any Send Connectors (Organisation Configuration > Hub Transport > Send Connectors)

Uninstall Exchange from Programs and Features.

Bulk AD Updates on OU

Posting this as I always bloody forget it!

import-module ActiveDirectory
Get-ADUser -SearchBase 'ou=users,dc=company,dc=local' -Filter * | Foreach-Object{
$firstname = $_.givenname
$lastname = $_.surname
$domain = "@company.co.uk"
$emailaddress = $firstname + "." + $lastname + $domain
Set-ADUser -Identity $_ -Email $emailaddress
}

Convert VHDx Files

https://technet.microsoft.com/en-us/library/hh848454.aspx

Example to convert from a dynamic to a fixed VHDx file:

Convert-VHD -path "C:\Hyper-V\server-1.VHD" -destinationpath "C:\Hyper-V\server-2.VHD" -vhdtype fixed

Once the VHDx has been altered the new file will not contain the correct permissions. If you rename the new VHDx to the same as the old file (after renaming the old one) then the Virtual Machine will not boot. If you examin the permissions of the two files you will see the differences. The simplest way to correct the permissions is to add the new VHDx through Hyper-V manager (or if you have renamed the VHDxs simply remove and re-add the Hard Drive in Hyper-V manager).

Exchange Message Queue Management

http://blogs.technet.com/b/messaging_with_communications/archive/2011/04/22/how-to-manage-exchange-2010-message-queues.aspx

Queues
Get-Queue
Resume-Queue
Retry-Queue
Suspend-Queue

Messages
Get-Message
Remove-Message
Resume-Message
Suspend-Message
Export-Messages

Live Migrations in PowerShell

If you get a hardware warning when attempting a live migration confirm that the Processor of the VM is configured, under Processor > Compatibility, to allow Migration to a different processor version. This is just a check box but the VM needs to be off to change it!

If you still get the error confirm that the virtual switch name on both Hyper-V boxes is the same. You will need to reboot the VM after you have updated them if you change the one on the Hyper-V host where the VM is currently.

Full powershell…

get-VM "VMtobeMoved" -ComputerName "NameofHyperVHost" | move-vm -DestinationHost "NameofDestinationHost" -VirtualMachinePath "D:\hyper-v\virtual machines\blah" -snapshotfilepath "D:\hyper-v\virtual machines\blah\" -SmartPagingFilePath "D:\hyper-v\virtual machines\blah\" -VHDs @(@{"sourcefilepath" = "c:\virtualmachines\blah\blah.vhd"; "destinationfilepath" = "D:\hyper-v\virtual hard disks\blah.vhd"}, @{"sourcefilepath" = "c:\virtualmachines\blah\virtual Hard Disks\blah-Data.vhd"; "destinationfilepath" = "D:\hyper-v\virtual hard disks\blah-Data.vhd"})

Hopefully you are sensible and all your Hyper-V files (machine, VHDs, snapshots, paging file, …) are all in one location. In which case you can use this much simpler script:

Get-VM "VMtobeMoved" -ComputerName "NameofHyperVHost" | Move-VM -DestinationHost "NameofDestinationHost" -IncludeStorage -DestinationStoragePath "D:\VMtobeMoved"