Archive

Archive for the ‘Powershell’ Category

[EXO] Various ways to grab all SMTP address from mailbox

February 19, 2021 No comments

 

Categories: Exchange, Powershell Tags:

[EXO] Identifying Validation Errors

July 27, 2020 No comments

$errors = (Get-MsolContact –ObjectID <Object_ID>).Errors
$errors | foreach-object {“nService: " + $_.ErrorDetail.Name.split("/")[0]; "Error Message: "+ $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}

$errors = (Get-MsolGroup –ObjectID <Object_ID>).Errors
$errors | foreach-object {"
nService: ” + $_.ErrorDetail.Name.split(“/”)[0]; “Error Message: “+ $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}

$errors = (Get-MsolUser -UserPrincipalName “<User_ID>”).Errors
$errors | foreach-object {“`nService: ” + $_.ErrorDetail.Name.split(“/”)[0]; “Error Message: ” + $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}

Get-MsolUser -HasErrorsOnly -All | ft DisplayName,UserPrincipalName,@{Name=”Error”;Expression={($_.errors[0].ErrorDetail.objecterrors.errorrecord.ErrorDescription)}} -AutoSize -wrap

https://support.microsoft.com/en-au/help/2741233/you-see-validation-errors-for-users-in-the-office-365-portal-or-in-the

 

 

Categories: Exchange, Office365, Powershell Tags:

[EXO][EX2010] Removing dual mailboxes

March 2, 2020 No comments

Ensure you have a user mailbox backup prior to starting the following process as there is potential risk of data loss.  Options are to have a third party solution to perform a mailbox backup or export to PST (see new-mailboxexport cmdlet).

  1. Capture relevant information from on-premise exchange and exchange online.
    • Grab the mailbox information (primary and archive) to help determine which mailbox is active and which one to disable (remove)
      • get-mailboxstatistics <user>
      • get-mailboxstatistics <user> -archive
      • get-exomailboxstatistics (exo ps v2)
    • Grab the x500 address (legacydn)
    • Grab GUID information
      • get-recipient <user> | fl *guid*
  2. Determine which mailbox is active and which one to disable (remove) – 
    1. Removing the on-premise mailbox will require you to delete and recreate the remote mailbox – an object on-premise will need to represent the object on exchange for remote routing.
      1. Disable the on-premise mailbox – do not remove, or you will remove the AD user object:
        • disable-mailbox <user>
      2. If litigation hold is enabled, you will need to disable the hold, then disable the mailbox.
      3. Recreate the remote mailbox on-premise
        • Enable-RemoteMailbox -Identity <user> -RemoteRoutingAddress “<user>@<tenant>.mail.onmicrosoft.com”
      4. Associate the GUID and x500 for sync and mail routing:
        • Set-RemoteMailbox -exchangeguid <exchange guid> -archiveguid <archive guid>  -EmailAddresses X500: <x500>
    2. Removing the cloud mailbox
      1. Remove the user from Office 365 and resync with AD sync.
        • remove-msoluser <user>
        • remove-msoluser <user> -removefromrecyclebin -force
      2. Clearing the previous mailbox information
        • Set-User <user> -PermanentlyClearPreviousMailboxInfo

Accidentally deleted a on-premise mailbox?

  1. Identify where the disconnected or soft deleted mailbox is. 
    • $dbs = Get-MailboxDatabase $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq “Disabled”} | Format-Table DisplayName,Database,DisconnectDate
  2. Reconnect the mailbox
    1. Connect-Mailbox -Identity “<identity>” -Database <database> -User “<user>” -Alias <alias>

Accidentally deleted the on-premise user, but need to restore the data to cloud mailbox?

  1. Create a new temporary mailbox on-premise to restore the data to.
  2. Identify where the disconnected or soft deleted mailbox is. 
    • $dbs = Get-MailboxDatabase $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq “Disabled”} | Format-Table DisplayName,Database,DisconnectDate,*guid*
  3. Restore the primary and archive data to the temporary mailbox
    • New-MailboxRestoreRequest -SourceStoreMailbox <mailbox guid> -SourceDatabase <database> -TargetMailbox <mailbox> -AllowLegacyDNMismatch
    • New-MailboxRestoreRequest -SourceStoreMailbox<mailbox guid> -SourceDatabase <database> -TargetMailbox <mailbox> -TargetIsArchive
  4. Export the data to PST (requires rights) 
    • NewManagementRoleAssignmentRole “Mailbox Import Export”User Administrator
    • New-MailboxExportRequest -Mailbox <mailbox> -FilePath <path>
    • New-MailboxExportRequest -Mailbox <mailbox> -FilePath <path> -isarchive
      • Ensure the Exchange Trust Subsystem group has read/write permissions to path
  5. Check status:
    • GetMailboxExportRequest | where {$_.status eq “Completed”}
  6. Remove job:
    • Get-MailboxRestoreRequest -Status Completed | Remove-MailboxRestoreRequest
    • Get-MailboxRestoreRequest -Status Failed | Remove-MailboxRestoreRequest
  7. Import to mailbox:
    • In Outlook with Exchange Online Mailbox, you can import directly – ensure you do not copy duplicates.
Categories: Exchange, Office365, Powershell Tags:

[EX2010][EXO] Forwarding Address Export and Import

February 11, 2020 No comments

 

Categories: Exchange, Office365, Powershell Tags:

Single mailbox export to PST file

January 22, 2020 No comments

Add member of a role group which has the Mailbox Import Export role

Export primary mailbox:

 

Export archive mailbox:

 

More details

https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/New-MailboxExportRequest?redirectedfrom=MSDN&view=exchange-ps

Categories: Exchange, Powershell Tags:

[PS][EX2010] E-mails Recieved per day of Month Report

October 9, 2019 No comments

.Synopsis
E-mail Counting Script v1 by ELAU 10/10/19
– Script counts emails received for each day of the current month
.DESCRIPTION
– Script pulls days of the month and counts number of emails received for each day of the current month or days specified into a HTML report.
– Script allows option to e-mail report
.EXAMPLE
– Run count.ps1 without parameters will prompt for required options
.EXAMPLE
– Specify days to go back without sending email report

count.ps1 -mailbox <mailbox to search> -day <days to search back from today>

.EXAMPLE
– Specify days to go back with sending email report

count.ps1 -mailbox <mailbox to search> -day <days to search back from today> -emailto <report to send to>

 

Categories: Exchange, Powershell Tags:

[PS] [EX2010] Recoverable Folder Size Report

Recoverable Folder Size Report v1

  • Crawls all mailboxes and pulls the recoverableitemsquota size
  • Displays top 10 in HTML report
  • Full CSV report is generated
  • E-mails report with full report

 

Categories: Exchange, Powershell Tags:

[EX2010][PS] Recover mail items from Exchange

August 15, 2019 No comments

How do I recover an item after its been deleted? So long as the recoverable items purge duration has not exceeded, you can run the below command to pull e-mails.

For more specific searchquery, reference Advanced Query Syntax (AQS).

  • Email 
  • Meetings 
  • Tasks 
  • Notes 
  • Docs 
  • Journals 
  • Contacts 
  • IM 

 

Categories: Exchange, Powershell Tags:

[PS] Enable TLS 1.2 as default in Powershell

August 5, 2019 No comments

Check Supported protocol

[Net.ServicePointManager]::SecurityProtocol

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

Change Net Frame to use TLS 1.2

Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord

Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord

 

Categories: Powershell Tags:

[EX2010] Litigation Hold (Legal Hold)

July 20, 2019 No comments

Litigation Hold (Legal Hold)

Used to preserve mailbox and electronically stored information in anticipation of legal proceedings, investigations, and unspecified reasons. Organizations may be required to inform when a user is placed on litigation hold.

Specifications:

  • Requires Discovery Management or Legal Hold Mgmt (RBAC) to place a mailbox in legal hold
  • Option to enable or disable, no option in 2010 to set start and end dates
  • Original copies are maintained when modified
  • LitigationHoldDate and LitigationHoldOwner attribute is created when enabled
  • Migration to O365: mailboxes on Litigation Hold are preserved after a mailbox is moved

Storage:

When a user deletes a folder other than in the Delete Items folder, the message is ‘moved’. When a user deletes from the Deleted Items folder or does a Shift+Delete (Permanent Deletion), the message disappears from the user’s view, is a ‘soft delete’ and moved to Purge sub-folder of the Recoverable Items folder (Recoverable Items folder is also known as the dumpster in previous versions of Exchange). Recoverable Items folder retains items configured on the mailbox database with a default of 14 days. If Litigation is not enabled, items are purged forever based on reaching the quota limit, or longer than the default or set period.

  • Default Quota for Recoverable Items Folder, Warning: 20GB, Items: 30 GB
  • MFA continues to process the mailbox
  • Deleted items are moved retained in a hidden folder called, Recoverable Items (dumpster) with its own storage, and does not count toward the mailbox quota.
  • Recoverable Items folder has 3 sub-folders:
    1. Deletions: Soft Deleted items are moved here, visible from Recoverable Deleted Items (Visible to users)
    2. Purges: Deleted items from the Recoverable Items are moved here. Deleted Items exceeding the delete item retention period configured on mailbox database or mailbox are also purged here by MFA. Litigation Hold prevents deletion of items from this folder when enabled. (Not visible to users)
    3. Versions: Original copies of mailbox items are copied here by process called copy on write, where in specific properties changes on the item will create a copy. (Not Visible to users)

Enable and Disabling Litigation Hold:

Checking Sizing for mailboxes in litigation hold:

Updating the Size for Recoverable Items when quota is reached:

 

Processing all Mailboxes in litigation hold:

References:

Understanding Litigation Hold

Retention Hold and Litigation Hold in Exchange 2010

Place a Mailbox on Litigation Hold

Categories: Exchange, Powershell Tags: