Showing posts with label Microsoft O365. Show all posts
Showing posts with label Microsoft O365. Show all posts

Restore emails from Old Mailbox (Inactive/Deleted) to New Mailbox

 If a user returns AFTER their Account has been deleted and is in inactive state.

 -          Must run a Restore, NOT a recover.   A recover will bring back the mailbox to the cloud and it can’t be linked to the newly created on prem AD account. 

-          Must create the new on prem account with a different name than the old account.   This will be temporary to restore the mailbox, then the account can be renamed to the same as the old account.

Procedure (Eg. John Smith – username was jsmith)

1.       Following the entire New User Setup instructions, create account j.smith

2.       Run this command to get the ExchangeGUID of jsmith’s inactive mailbox:

Get-Mailbox -InactiveMailboxOnly | FL Name,DistinguishedName,ExchangeGuid,PrimarySmtpAddress

3.       Run this command to store the inactive mailbox to a variable

$InactiveMailbox = Get-Mailbox -InactiveMailboxOnly -Identity <ExchangeGUID>

4.       Run this command to copy contents of inactive jsmith mailbox to new j.smith mailbox

New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -TargetMailbox j.smith@xyz.com -AllowLegacyDNMismatch

5.       Run this command to see progress of restore

Get-MailboxRestoreRequestStatistics -Identity "Username\MailboxRestore"

6.     If there is an archive, run this command to restore archive from jsmith to j.smith:

New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -SourceIsArchive -TargetMailbox j.smith@xyz.com -TargetIsArchive -TargetRootFolder "Inactive Mailbox Archive" -AllowLegacyDNMismatch

7.       Run this command to see progress of restore

Get-MailboxRestoreRequestStatistics

8.     Once the restore is complete, rename the AD account and Exchange alias to jsmith. Edit email addresses to remove all entries for j.smith

9.     Have user login and verify they have the contents of their old mailbox

10 . Delete inactive mailbox.

Send SMTP email from powershell script (SMTP Auth)


************************************* being script ***************

#OFFICE 365 working

$email_username="username@xyz.com"

$email_password = ConvertTo-SecureString -string "password" -AsPlainText -Force;

$email_smtp_host = "smtp.office365.com";

$email_smtp_port = 25;

$email_smtp_SSL = 1;

$email_from_address = "username@xyz.com";

$email_to_addressArray = @("himanshu@test.in");

$credential=New-Object System.Management.Automation.PSCredential($email_username,$email_password);

 

cls

 

Send-MailMessage -From "$email_from_address" -To $email_to_addressArray -Subject "Test email from powershell" -Body "This is only a test" -SmtpServer $email_smtp_host -Credential $credential -UseSsl -Port $email_smtp_port



********************************** END ************************

Get distribution list send as permission (Exchange Online)

Get list of users having "send as" permission on distrition list (Exchange Online)

Get-RecipientPermission -Identity test@xyz.com

Get Mailbox Folder Size

Article - Get Mailbox Folder Size from Exchange using PowerShell (morgantechspace.com)

Get Mailbox Folder Size from Exchange using PowerShell

We can use the Exchange Powershell cmdlet Get-MailboxFolderStatistics to list all the available folders in a specific user mailbox or shared mailbox. This command also helps to get the size and no of items in every folder and subfolders.  This cmdlet is available for both on-premises Exchange and Microsoft Office 365 (Exchange Online) services. Before start, run the following command to connect Exchange Online module.

1
Connect-ExchangeOnline

The following command just extracts all the folders from the given user mailbox (ex: Alex) along with folder size and the number of items in the folder.

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" |`
Select Name,FolderSize,ItemsinFolder

The above command individually returns folder and subfolder sizes, we need to select the field FolderAndSubfolderSize to get the size of the folder and subfolders. 

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" |`
Select Name, FolderAndSubfolderSize ,ItemsInFolderAndSubfolders

We can get specific folder and subfolder details by using the -FolderScope parameter.  The following command lists the “Inbox” folder and all the subfolders that are created under the Inbox folder.

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" -FolderScope Inbox |`
Select Name,FolderSize,ItemsinFolder

Instead of getting subfolder sizes individually for the Inbox folder, we can filter only the Inbox folder and select the field FolderandSubFolderSize which returns the entire Inbox folder size.

1
2
3
Get-MailboxFolderStatistics "AlexW@contoso.com" -FolderScope Inbox |`
Where {$_.FolderPath -eq "/Inbox"} |`
Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Get Root or Non-IPM subtree folders

By default, the Get-MailboxFolderStatistics cmdlet returns IPM subtree (IntraPersonal Messaging) folders. The IMP subtree is a structure of folders intended to handle messages between human recipients, such as Inbox or Sent items.

Alon with IMP subtree folders, we will also have Root-level folders, also known as Non-IPM subtree (Non-Interpersonal Messaging). The Non-IPM subtree represents a hierarchy of folders at the root level used for storing special data and metadata created and consumed by different features and services such as Microsoft Teams private chat (1 to 1 chat). The copy of Team private chat messages will be stored in the special folder “TeamsMessagesData” (or TeamChatHistory) in the associated user mailbox. 

Run the following command to retrieve the Non-IPM subtree or Root level or special folders.

1
2
Get-MailboxFolderStatistics  "Admin@contoso.com" -FolderScope NonIPMRoot |`
Select Name,FolderSize,ItemsinFolder

Export Specific Folder Size for all Mailboxes

The following script retrieves the size of inbox folder of all user mailboxes in the organization.  The result will be exported to a CSV file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$Result=@()
$mailboxes Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$totalmbx = $mailboxes.Count
$i = 1
$mailboxes | ForEach-Object {
$i++
$mbx = $_
$folderstats = Get-MailboxFolderStatistics $mbx.Identity -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"}
 
Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"
  
$Result += New-Object -TypeName PSObject -Property $([ordered]@{
Name = $mbx.DisplayName
UserPrincipalName = $mbx.UserPrincipalName
InboxSizeInMB = [math]::Round(($folderstats.FolderandSubFolderSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
InboxItems = $folderstats.ItemsinFolderandSubfolders })
}
  
$Result | Export-CSV "C:\InboxFolderSizes.csv" -NoTypeInformation -Encoding UTF8