Increase/Decrease deleted item retention for licensed mailboxes
Get-Mailbox -ResultSize unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" | Set-Mailbox -RetainDeletedItemsFor 30
For all new Mailboxes:
Get-MailboxPlan | Set-MailboxPlan -RetainDeletedItemsFor 30
Verify:
Get-Mailbox <Name> | Format-List RetainDeletedItemsFor
Get-Mailbox -ResultSize unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" | Format-List Name,RetainDeletedItemsFor
-Only applicable to licensed mailboxes (not shared)
-This time would likely need to be reduced if the user needs to complete a large delete operation (I ran into this issue with [retiring employee's] Mailbox, and I had to decrease the amount of items in his mailbox so I could convert it to a shared Mailbox), although realistically this should never be done. Enable Archive and move items, increase mailbox size, or wait for retention period to expire. Retention period can also be decreased manually on the individual mailbox.
https://docs.microsoft.com/en-us/powershell/module/exchange/set-mailboxplan?view=exchange-ps
-Side note - if archive is already enabled they may be moved to the Archive mailbox although I haven't been able to test it. See below from Exchange Admin Center -> Compliance management -> retention policies
Currently, one of the steps when setting a user account as inactive is marking the mailbox as hidden from the GAL. This declutters the address list, and makes it so name of people who no longer work at the company autocomplete. Here is a simple one-liner to get a list of mailboxes that are Shared Mailboxes, but are not hidden from the GAL:
Get-Mailbox -Filter {recipienttypedetails -eq "SharedMailbox"} | Where {$_.HiddenFromAddressListsEnabled -eq $False}
This will test all Shared Mailboxes, so some of these may not be hidden from the GAL on purpose, but in my case all ex employee accounts were marked as a Shared Mailbox, then hidden from the GAL.
Check the size of all Archive Mailboxes in the org. Luckily, there weren't many in my case
Get-Mailbox -Archive -resultsize unlimited | Select-Object name,@{n="Archive Size";e={(Get-MailboxStatistics -archive $_.identity).TotalItemSize}}
When I ran this again for the heck of it, for some reason the total archive size was blank for some people. To get the size of individual archive mailboxes, you could go through the Exchange Admin Center or run
Get-MailboxStatistics -Identity john@test.com -Archive | Select DisplayName, TotalItemSize,ItemCount
Set a list of mailboxes as Shared Mailboxes
$content = get-content "P:\Jacob_IT\users4.txt" <-- Path to text file with only a list of email addresses (unique)
foreach ($user in $content) {
Set-Mailbox -Identity $user -Type Shared}
(This command has no verbose and is rather slow, be patient)
Verify with:
foreach ($user in $content) {
Get-ExoMailbox -Identity $user | Format-List RecipientTypeDetails}
Get usage for all individual OneDrive storage
Connect-SPOService [Admin URL]
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" | Select URL, Owner, StorageQuota, StorageUsageCurrent, LastContentModifiedDate
When a SharePoint folder is synced to a computer with OneDrive, it is extremely easy to delete it. See the below command for a quick way to restore files deleted by a particular user, within a particular date range. When I ran this, it came up with some folder name conflicts, but I was able to manually restore those files from the SharePoint recycle bin and ran into no issues.
Connect-PnpOnline [Site URL] -Interactive
Get-PnPRecycleBinItem | ? {($_.DeletedDate -gt "05/14/2022" -and $_.DeletedDate -lt "05/18/2022") -and ($_.DeletedByEmail -eq 'usert@domain.com')} | Restore-PnpRecycleBinItem -Force
Also useful to export a report of all deleted items to a csv, which can then be sorted in Excel:
Get-PnPRecycleBinItem | Export-Csv C:\Users\jacob.amrine\export.csv