PowerShell – New-ComplianceSearch script to go through all mailboxes, find a target message, and remove it

Here is another more advanced script that searches for messages of interest, then optionally exports and purges them. So, what makes this script more advanced? Unlike the other script that uses Search-Mailbox ( https://365basics.com/powershell-search-mailbox-script-to-go-through-all-mailboxes-find-a-target-message-and-remove-it/ ) this script below is based on New-ComplianceSearch cmdlet: Pros: Super fast, multi-threaded, takes about 1-2 minutes on average to complete the whole task. As Microsoft is trying to depreciate Search-Mailbox, they put more effort into New-ComplianceSearch, so we can expect new functionality to come in the future. Can create an export file that can be downloaded and investigated. Cons: Always searches through all folders including Purged Items which might create some confusion when showing results (if running the same search again) - see UPDATE 9/30/2019 Cannot copy messages to another mailbox for you to investigate. Of course there are quite a few scripts out there that use New-ComplianceSearch, everyone has their own approach. So let…

Continue ReadingPowerShell – New-ComplianceSearch script to go through all mailboxes, find a target message, and remove it

PowerShell – Search-Mailbox script to go through all mailboxes, find a target message, and remove it

When looking at the title of this post, one might notice I used a target word, and it is on purpose. This script below is useful when trying to remove all types of messages from users' mailboxes whether it's a spam, scam, virus or a an important message that needs to be "recalled". This script is based on Search-Mailbox cmdlet, works well but it has its own pros and cons, more on some of them below. Later I will have another post showing a different and more advanced script to do the same and even better. So stay tuned. Pros: Doesn't search through Purged Items (a bit more about the 3rd layer of Trash is here - https://365basics.com/script-to-search-through-recoverable-and-purged-items-and-restore-those/ ). Can copy messages to another mailbox (IT Help in that example). Cons: Per Microsoft Search-Mailbox will be depreciated, we don't know when it will happen though. Slow (if a target message…

Continue ReadingPowerShell – Search-Mailbox script to go through all mailboxes, find a target message, and remove it

PowerShell – change the storage space for a specific user’s OneDrive

As an admin you can easily make an adjustment of a OneDrive storage limit for all users through a OneDrive admin center. If you need to do the same for a specific user, here is a Microsoft article that describes that - https://docs.microsoft.com/en-us/onedrive/change-user-storage Truth is, it only takes a single line of code to make an adjustment; however, my script below takes care of most little things, requirements, and inconveniences: you only need an email address of a user; the minimum size of allocated space is 1 GB; the maximum size is 5 TB. $email = Read-Host "Please provide an email address of the user" $convertedemail = $email -replace "\.","_" -replace "@","_" $partofthelink = "-my.sharepoint.com/personal/" + $convertedemail $onedriveurl = Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like $partofthelink" $onedriveurl Do { Try { $num = $true [int]$sizegb = Read-Host "Please specify the size of OneDrive storage space to be set…

Continue ReadingPowerShell – change the storage space for a specific user’s OneDrive

PowerShell – show and adjust resource booking configuration according to 4 scenarios

There is an amazing article (https://itpro.outsidesys.com/2017/11/06/exchange-configuring-the-resource-booking-attendant-with-powershell/) published by John Dougherty on how to adjust resource booking configuration having 4 different scenarios. Those 4 scenarios are: Anyone can book the resource. No delegate approval required. Anyone can book the resource. Delegate approval required for all requests. Only a list of people can book the resource without delegate approval. All others require delegate approval. Only a list of people can book the resource. All others are denied. There are no delegates. Not everything can be done through an Admin portal, that's why having such a PowerShell script is crucial. I decided to do several things to improve that process: Added code to check an existing configuration for every single Room and Resource. If the configuration is any different than these 4 above, then the script notifies you about it. Combined scripts into a single one. Added more user input to not adjust the…

Continue ReadingPowerShell – show and adjust resource booking configuration according to 4 scenarios

Script to search through Recoverable and Purged items and restore those

The purpose of this script is to find deleted messages in a specified user's mailbox. There are 3 levels (when configured) of Trash in a mailbox: Level 1 - Deleted Items (e.g. 30 days) Level 2 - Recoverable items (e.g. 15 days) Level 3 - Purged items (e.g. 15 days) Users usually know about the first two. Moreover, they can only work with the first two from both Outlook and OWA. Only admins have access to Purged items. It makes sense to use this script in at least 2 cases: A user is being terminated on bad terms, decided to permanently delete everything from both Deleted and Recoverable items. A user deleted an email at some point, missed the first 30-day period, then missed the second 15-day period, and then wants to recover that email. If it's less than 60 days (30+15+15) overall then that email can be restored. The script…

Continue ReadingScript to search through Recoverable and Purged items and restore those

Script to add or replace distribution groups of a target user with groups a source user has

This PowerShell script has two use cases combined in it - ADD and REPLACE. Before any change is made the script also shows a group membership for both a target and a source users. Note, the script only processes those distribution groups that are managed in the cloud. If you have some groups synced with Active Directory, those should be processed separately. USE CASE #1 - ADD When Add is chosen, the scripts only adds distribution groups of the source user to the target user's list. Use this part of the script when a target user assumes new responsibilities that another user has but keeps the old responsibilities as well. In other words, the target user needs to have a combination of new and old distribution groups to perform job tasks. USE CASE #2 - REPLACE Essentially, the 2nd part of the script is a combination of the 1st part…

Continue ReadingScript to add or replace distribution groups of a target user with groups a source user has

Script to removeĀ a user from all distribution groups managed in the cloud

The purpose of this PowerShell script is to remove a user from all distribution groups. The script is interactive, it will show the list of groups first, then you have an option to process your request. While the same can be done using Exchange Admin or Microsoft 365 Admin Center, it is much faster using PowerShell. Note, the script only processes those distribution groups that are managed in the cloud. If you have some groups synced with Active Directory, those should be processed separately. $email = Read-Host "Please provide a user's email address to remove from all distribution groups" $mailbox = Get-Mailbox -Identity $email $DN=$mailbox.DistinguishedName $Filter = "Members -like ""$DN""" $DistributionGroupsList = Get-DistributionGroup -ResultSize Unlimited -Filter $Filter Write-host `n Write-host "Listing all Distribution Groups:" Write-host `n $DistributionGroupsList | ft $answer = Read-Host "Would you like to proceed and remove $email from all distribution groups ( y / n )?" While…

Continue ReadingScript to removeĀ a user from all distribution groups managed in the cloud

Script to get mailbox size and number of items info for all users or a single one

This script has two parts in it and depending on the selection it will either run it against a single specified mailbox or all of them at once. Note, running this script against a few hundred mailboxes takes several minutes. So if your company is large with thousands of mailboxes, expect it to take much longer. As part of the output it lists the following parameters - a user name, number of items in the mailbox, its current size, and a maximum allowed size. There is a downside of using this script when running it against all mailboxes. Because Get-MailboxStatistics outputs TotalItemSize as a string only, it makes it harder to search through and sort by. I wish Microsoft could change that and provide data in a number type format. $answer = Read-Host "Would you like to get statistics for all users ( y / n )?" While ("y","n" -notcontains $answer)…

Continue ReadingScript to get mailbox size and number of items info for all users or a single one

Script to turn a Shared Mailbox into an automated calendar only or a combination of both

The purpose of this PowerShell script is to adjust an existing Shared Mailbox to auto-accept calendar invitations and either keep emails or automatically remove them. Why would you do that as an admin? Well, there are 2 scenarios for it, and the choice really depends on the department / team in your company and their needs: 1) Its only purpose is a Calendar (e.g. team calendar for vacations) 2) Its purpose is a combination of a Calendar and a Mailbox (e.g. Help Desk mailbox and team calendar for vacations combined rather than two entities separately). Regardless, the way it works for users - they invite that calendar as a participant when creating vacation bookings. Thus, those bookings will be visible in both a personal calendar and a team calendar. What this script does: Turns on auto-processing; Allows conflict creation; Either deletes emails or keeps them depending on a scenario from…

Continue ReadingScript to turn a Shared Mailbox into an automated calendar only or a combination of both

Script to show my computer name and IP address

If you need to know the name of the computer of a user or the IP address, then this tiny PowerShell script can become handy. For example, that information might be required for remote assistance software. There are some tools out there that show this info, e.g. BgInfo, but they don't always work. Moreover, some users insist on seeing an unobstructed photo of their puppy they just got from a shelter. That's a big one! 1) Create a PowerShell script file with this content: Add-Type -AssemblyName System.Windows.Forms $ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1} $ipaddress = $ip.ipaddress[0] $pcname = [System.Net.Dns]::GetHostName() [System.Windows.Forms.MessageBox]::Show("My PC name - $pcname `n`nMy IP address - $ipaddress",'About my PC','OK','Information') This script is a modified combination of scripts out there that other people made, so by no means I'm trying to take any credits for it. 2) Put this script to a network location that every user has Read access to.…

Continue ReadingScript to show my computer name and IP address