Federated Trust for Hybrid Environment

Add a Federated Trust using powershell for a Hybrid Environment

 

-Production on-premies powershell

PS H:> Get-FederationInformation -DomainName Friendly.onmicrosoft.com -BypassAdditionalDomainValidation | New-OrganizationRelationship “Friendly Online” -FreeBusyAccessEnabled $true -FreeBusyAccessLevel AvailabilityOnly

 

-Production cloud powershell

PS H:> Get-FederationInformation -DomainName Friendly .onmicrosoft.com -BypassAdditionalDomainValidation | New-OrganizationRelationship “Friendly Online” -FreeBusyAccessEnabled $true -FreeBusyAccessLevel AvailabilityOnly

 

-From outside company powershell

PS H:> New-OrganizationRelationship -Name “your company” -DomainNames “your company”.mail.onmicrosoft.com, “your company”.onmicrosoft.com,”Your company”.edu -FreeBusyAccessEnabled $true -FreeBusyAccessLevel AvailabilityOnly -TargetApplicationUri outlook.com -TargetAutodiscoverEpr https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc/WSSecurity -Enabled $true

 *NOTE: cloud to cloud free busy search you will have to use the target addresses e.g someone@company.mail,onmicrosoft.com

 

EWS Script: Move email items based on received date into a folder

Scenario:  You want to move email items based on date range into a folder.

Script:  The script performs the following:

  1. Attaches to the mailbox specified in the script
  2. Looks in the inbox for email items with a received that lies between a date range.
  3. Creates a folder
  4. Moves those items into that folder.
#Make sure the account you run this as has full access permissions to the mailbox

#Load the EWS Assembly
    Import-Module -Name "C:Program FilesMicrosoftExchange ServerV15BinMicrosoft.Exchange.WebServices.dll"

    $service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.Exchangeversion]::exchange2013)

    $service.Url = new-object System.Uri("https://Ex2013Srv1/EWS/Exchange.asmx")


#Define your Variables
    #$StartDate = [system.DateTime]::Today.AddDays(-1)
    #$EndDate = [system.DateTime]::Today
    #OR
    [datetime]$StartDate  = "11/17/2015"
    [datetime]$EndDate = "11/18/2015"
    $mailboxname = "steve@domain.com"

#Bind your Folder & Create your filter
    $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
    $InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    $Sfgt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $StartDate)
    $Sflt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsLessThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $EndDate)


#Create Collection and Apply your Filter
    $sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);
    $sfCollection.add($Sfgt)
    $sfCollection.add($Sflt)
    $view = new-object Microsoft.Exchange.WebServices.Data.ItemView(2000)
    $frFolderResult = $InboxFolder.FindItems($sfCollection,$view)


#Creates a Folder
    $NewFolder = new-object Microsoft.Exchange.WebServices.Data.Folder($service)
    $NewFolder.DisplayName = $EndDate.ToString("yyyy-MM-dd")
    $NewFolder.Save($InboxFolder.Id.UniqueId)


#Moves your Email Items
    foreach ($miMailItems in $frFolderResult.Items){
    "Moving:" + $miMailItems.Subject.ToString()
    [VOID]$miMailItems.Move($NewFolder.Id)
    }

	

Detect Backpressure on your Exchange Servers

Scenario:  Customers are complaining about connectivity issues and degraded performance with their mail clients. You suspect its due to backpressure on a server, but you want to dig a little deeper.

Troubleshooting:

1.Check for Windows Event 2002 “The number of outstanding requests for guard TargetBackend has exceeded the max limit 150. Current request will be rejected” by running this PowerShell command:

Get-WinEvent -computername <remote computer> -FilterHashtable @{logname=’application’;id=2002}

 

2. Check the number of mounted copies of mounted Exchange Databases on each server and manually spread them out:

(get-mailboxdatabasecopystatus -server <remote computer> | Where status -like Mounted).count

3. Check for user counts and compare against each server by running this Powershell Command:

(Get-WmiObject Win32_LoggedOnUser -ComputerName <remote computer>| Select Antecedent -Unique).count

Error: “You cannot migrate mailbox off of Office365 while the mailbox has a connected account enabled.”

Scenario:  When offboarding a mailbox, you receive the following error:

“You cannot migrate mailbox  off of Office365 while the mailbox has a connected account enabled.”

Solution: You will have to remove the subscription before offboarding the mailbox.

First,  check the subscription to make sure its not anything that’s going to affect the user:

get-subscription –mailbox stevem| FL IncomingServer, SubscriptionType, *Status*, LastSuccessfulSync,IncomingUserName

If it all looks good, run the following to remove the subscriptions:

get-subscription -mailbox stevem | Remove-subscription

 

Remove HTML Tags from a PowerShell string or Variable

Scenario:  A variable stores a value that has HTML tags.  You wish to remove all the HTML tags from the variable but keep the content.

Example:   Running the following will store the internal message of Out of Office in the variable $1.

$1 = (Get-mailboxautoreplyconfiguration steve).internalmessage

When displaying $1, it looks like this:

<div class=”BodyFragment”>
<font size=”2″><span style=”font-size:10pt;”><div class=”PlainText”>Steve has left the building. He is never coming back .<br>
</div></span></font>
</div>

 

Scriptlet:

$1 = $1 -replace ‘<[^>]+>’,”

When displaying $1, it will now look like this:

Steve has left the building. He is never coming back.

Need to recreate Arbitration Mailboxes as they are no longer available

Scenario:  You have arbitration mailboxes that are located on databases that are no longer accessible.   Although the mailbox is no longer accessible, the AD User account is still in tact.

Solution:  Disable and re-enable the arbitration mailboxes.  The Database DB04 is where the arbitration mailboxes lived but DB04 is gone.

Set-adserversettings -viewentireforest:$true

$1 = get-mailbox -arbitration | Where Database -like DB04 

$1 | Disable-mailbox -confirm:$false

$1 | Enable-mailbox

The Error: Couldn’t disable the arbitration mailbox because it is associated with existing recipients for which membership restriction of approval is required or the moderation feature is enabled. Please disable the approval feature on those recipients before performing this operation.

Scenario:  You receive the following error when trying to disable/remove an arbitration mailbox:

Couldn’t disable the arbitration mailbox because it is associated with existing recipients for which membership restriction of approval is required or the moderation feature is enabled. Please disable the approval feature on those recipients before performing this operation.

Solution:  Locate the distribution groups that are using this arbitration mailbox.  You will be able to transfer the arbitration mailbox used by the distribution groups if you have another.

Get-distributiongroup  | Select Name, ArbitrationMailbox

OR

Get-distributionGroup | Where ArbitationMailbox -like “Domain.Com/Users/SystemMailbox{149831f20381-30d4-ed31-1345defe2313”

You can use the opposite to set it to the new Arbitation mailbox:

set-distributiongroup -identity “name of Distribution Group” -arbitrationmailbox “name of Arbitration Mailbox”

Perform an NSLookup in PowerShell to find the IP Address(es) tied to a hostname

Scenario:  You want to perform an NSLookup in PowerShell so you can use the multiple IP addresses that you are using for DNS Round Robin in another PowerShell Query.

Solution: Run the following:

#Collect the IP Addresses of the hostname into a variable
$address = [system.net.dns]::GetHostAddresses("mail.domain.com" | Select IPAddressToString)

#For Each Loop it with a command
$address | Select -expandproperty IPAddressToString | %{ Get-ADComputer $_ }

 

Determine which Windows Management Framework is installed in PowerShell

Scenario: You want to easily detect which Windows Management Framework is installed on your server.

Solution:

Run either in Powershell

host  | Select Version

OR

$PSVersionTable.PSVersion