How to manage Enterprise environments - Part 2 - Creating PowerShell scripts with a Filtered query

Tutorials in this series - 
How to manage Enterprise environments - Part 1 - Filtering queries - Link
How to manage Enterprise environments - Part 2 - Creating scripts with a filtered query - Link
How to manage Enterprise environments - Part 3 - Bulk management using multiple filters - Link

-----------------------------------------------------------------------------------------------

How to manage Enterprise environments
Part 2 - Creating PowerShell scripts with a Filtered query

Previously -

In my previous tutorials I have showed how to create basic PowerShell scripts using the import-csv and export-csv functionalities.

This knowledge will help you create scripts for your daily reports and administration.
However sometimes, due to the size and complexity of your organization, you may need to create a filtered query to help refine your target. The best way to do this is to create a PowerShell script that uses a filtered query.

There are countless 'queries' that you can perform using this method and I will run through a few options which will help you manage what sometimes may look unmanageable. The following examples will provide inspiration on how you can create filtered queries for your day to day management.

----------------------------------------------------------------------------------------------

Example 1 - 
Filtered Query using Custom Attributes -
Get-Mailbox -ResultSize "unlimited" -Filter {CustomAttribute1 -eq "Managed Account"} |
Get-MailboxStatistics |
Select DisplayName,Database,DatabaseName,ServerName,ItemCount,TotalItemSize,AttachmentTableTotalSize |
export-csv -NoTypeInformation c:\scripts\MailboxStatistics-ManagedAccounts.csv

Below is the csv file that is generated.




----------------------------------------------------------------------------------------------

Example 2 - 
Filtered Query using Mailbox Type -
Get-Mailbox -ResultSize "unlimited" -Filter {RecipientTypeDetails -eq "SharedMailbox"} |
Get-MailboxStatistics |
Select DisplayName,Database,DatabaseName,ServerName,ItemCount,TotalItemSize,AttachmentTableTotalSize |
export-csv -NoTypeInformation c:\scripts\MailboxStatistics-SharedMailboxes.csv

Below is the csv file that is generated.





-----------------------------------------------------------------------------------------------

Example 3 - 
Filtered Query using Active Directory / Exchange Attribute -
Get-Mailbox -ResultSize "unlimited" -Filter {Office -eq "Singapore"} |
Get-MailboxStatistics |
Select DisplayName,Database,DatabaseName,ServerName,ItemCount,TotalItemSize,AttachmentTableTotalSize |
export-csv -NoTypeInformation c:\scripts\MailboxStatistics-SingaporeOffice.csv

Below is the csv file that is generated




----------------------------------------------------------------------------------------------

Congratulations - You now have the knowledge to create basic PowerShell scripts using a filtered query.

Now continue on to learn how to put all this knowledge together to 
- Use a filtered query script to target certain users and create a csv file
- Import that csv file generate targeted reports and targeted bulk administration

Continue on to Part 3 - Link
How to manage Enterprise environments - Part 3 - Bulk management using multiple filters - Link

--------------------------------------------------------------------------------------------------

Basic PowerShell Tutorials
01. How to configure your desktop PC for Office 365 Administration - Link
02. How to connect to Office 365 via PowerShell - Link
03. How to create basic PowerShell scripts - Link
04. How to create basic PowerShell scripts with Export-CSV - Link
05. How to create basic PowerShell scripts with Import-CSV - Link

Series Tutorials -
How to manage Enterprise environments - Part 1 - Filtering queries - Link
How to manage Enterprise environments - Part 2 - Creating scripts with a filtered query - Link
How to manage Enterprise environments - Part 3 - Bulk management using multiple filters - Link

Tips and Tricks
General Tips and Tricks for better Office 365 Administration - Link
How to extend your Office 365 Trial - Link
How to get a 180 day trial tenant in Office 365 for testing - Link

---------------------------------------------------------------------------------------------------

No comments:

Post a Comment