1. <#Import in modules, if statement for PSSnapin so that it doesn't throw
an error if it is already loaded.#>
Import-Module ActiveDirectory
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin -
ErrorAction SilentlyContinue) -eq $null )
{
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
}
<#Clear variables so they are not retaining any old values#>
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0
<#Variables needed to complete script. Domain OU and AD Servers#>
$ausOneOffOU = "OU=One-Off user
mailbox,OU=Users,OU=Corporate,DC=austin,DC=kmvtechnologies,DC=com"
$ausDC = "SanitizedServerName.austin.kmvtechnologies.com"
$ausCred = Get-Credential -Message "This is the AUSTIN domain" -
ErrorAction Stop
<#Create an Array from Get-mailbox cmdlet that has the value
"LinkedMailbox" tying it to a Corporate account, .count value used to
check results against expected#>
$mailboxes = Get-Mailbox -resultSize unlimited -RecipientTypeDetails
usermailbox -Verbose
foreach ($mailbox in $mailboxes){
Get-ADUser $mailbox.SamAccountName -Server $ausDC -Credential
$ausCred -Verbose | Move-ADObject -TargetPath $ausOneOffOU -Server
$ausDC -Credential $ausCred -Verbose -ErrorAction Stop
}