Skip to content

Instantly share code, notes, and snippets.

@tostka
Last active July 17, 2019 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tostka/dae1a35c11409bf1f24a1758c8b7a880 to your computer and use it in GitHub Desktop.
Save tostka/dae1a35c11409bf1f24a1758c8b7a880 to your computer and use it in GitHub Desktop.
Confirm No-Brain mbx status
# populate the DistName string below with a DN pointed at the target unreplicated OU
$tOU=get-adobject -Identity 'OU=Workspace,DC=global,DC=ad,DC=toro,DC=com' ;
# store the original ADUser object parentOU (split DN and build the parent OU)
$origOU=($adu.distinguishedname.split(",") | select -skip 1) -join "," ;
# move the ADUser object to the $tOU, note -whatif needs to be removed to execute
Move-ADObject -Identity $adu.ObjectGUID.guid -TargetPath $tOU.DistinguishedName -whatif ;
# NO WHATIF AVAILABLE for remove-msoluser!
remove-msoluser -userprincipalname $adu.userprincipalname ;
# run again to remove from dumpster
remove-msoluser -userprincipalname $adu.userprincipalname -removefromrecyclebin -force ;
# note -whatif needs to be removed to execute
set-aduser -Identity $adu.samaccountname -clear msExchMailboxGuid, msexchrecipientdisplaytype, msexchrecipienttypedetails -whatif;
# confirm attributes cleared
get-aduser -Identity $adu.samaccountname -prop * | format-list msExchMailboxGuid, msexchrecipientdisplaytype, msexchrecipienttypedetails ;
# confirm $origOU was properly configured up in step 1.
$origOU ;
# move the ADUser object to the $origOU, note -whatif needs to be removed to execute
Move-ADObject -Identity $adu.ObjectGUID.guid -TargetPath $origOU -whatif ;
# confirm current location
get-aduser $adu.samaccountname | format-list dist* ;
# AAD replication dawdle loop:
# 1-line, note, the get-msoluser cmdlet lacks an erroraction param, which causes it to error every pass. But the code plows on until object is returned replicated
Do { write-host "." -NoNewLine; $msolu = get-MsolUser -UserPrincipalName $adu.userprincipalname ; start-sleep -s 30 ; } Until($msolu) ; write-host "`a" ; write-host "`a" ; write-host "`a" ; $msolu | format-list userprin*, *Error*, *status*, softdel*, lic*, islic* ;
$msolu = get-MsolUser -UserPrincipalName $adu.userprincipalname ; $msolu | format-list userprin*, *Error*, *status*, softdel*, lic*, islic*
rxo ; get-exomailbox $tAddress ; rx10 ; get-recipient $tAddress | ft -a Name, RecipientT* ;
$whatif = $true ;
$exombx = get-exomailbox $tAddress ;
$RemoteRoutingAddress = ($exombx.emailaddresses | ? { $_ -match '.*.mail\.onmicrosoft\.com' }).replace("smtp:", "");
$pltEnable = [ordered]@{
Identity = $exombx.alias ;
RemoteRoutingAddress = $RemoteRoutingAddress ;
whatif = $($whatif) ;
} ;
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):Enable-RemoteMailbox w`n$(($pltEnable|out-string).trim())" ;
Enable-RemoteMailbox @pltEnable;
if (!$whatif) {
$pltSet = [ordered]@{
Identity = $exombx.alias ;
ExchangeGuid = $exombx.ExchangeGuid ;
whatif = $($whatif) ;
} ;
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):Set-RemoteMailbox w `n$(($pltSet|out-string).trim())" ;
Set-RemoteMailbox @pltSet ;
get-remotemailbox -id $exombx.alias | select userprin*, samac*, recipientt* ;
} ;
$whatif=$true ;$exombx=get-exomailbox $tAddress ;$RemoteRoutingAddress=($exombx.emailaddresses |?{$_ -match '.*.mail\.onmicrosoft\.com'}).replace("smtp:","");$pltEnable=[ordered]@{ Identity=$exombx.alias ; RemoteRoutingAddress=$RemoteRoutingAddress ; whatif=$($whatif) ;} ;write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):Enable-RemoteMailbox w`n$(($pltEnable|out-string).trim())" ;Enable-RemoteMailbox @pltEnable;if(!$whatif){ $pltSet=[ordered]@{ Identity=$exombx.alias ; ExchangeGuid=$exombx.ExchangeGuid ; whatif=$($whatif) ; } ; write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):Set-RemoteMailbox w `n$(($pltSet|out-string).trim())" ; Set-RemoteMailbox @pltSet ; get-remotemailbox -id $exombx.alias | select userprin*,samac*,recipientt* ;} ;
get-exomailbox $tAddress ; get-recipient $tAddress | ft -a Name, RecipientT* ;
get-exomailbox $tAddress ; get-recipient $tAddress | ft -a Name, RecipientT* ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment