Skip to main content

8 Useful PowerShell Commands

By February 1, 2016December 26th, 2018Tech

Useful Powershell Commands
Below you will find 8 PowerShell commands that will be useful to any Business Owner who has a Server and wants to do some technical work, or for any System Administrator that deals with user and email accounts on a daily basis.

Keep in mind that email related commands need to be entered in Exchange Management Shell and Windows related commands in Windows PowerShell.


Useful PowerShell Commands

  1. 1. Hide all Disabled Users from the GAL in Exchange
  2. Get-Mailbox -OrganizationalUnit "Disabled Users" | Set-Mailbox -HiddenFromAddressListsEnabled $true

    Replace Disabled Users with the name of the Organizational Unit that contains the users you would like to Hide from the Exchange address lists.


  3. 2. Force the Global Address Book to Update
  4. Get-GlobalAddressList | update-GlobalAddressList
    Get-AddressList | update-AddressList
    Get-OfflineAddressBook | Update-OfflineAddressBook


  5. 3. Export users from a specific Security Group to a .csv file.
  6. Get-ADGroupMember SG-Finance | select name | Export-Csv c:\finance.csv

    Replace SG-Finance with the Security Group you would like to export users from.


  7. 4. Export a list of users that have access to a specific Public Folder and their Permissions to a .csv file
  8. Get-PublicFolderClientPermission "\Finance" | select user, AccessRights | export-csv C:\finance.csv

    Replace Finance with the folder you want.


  9. 5. Find a user’s Username using Email
  10. get-recipient <"email address">


  11. 6. List all files in a folder & export them to a .csv file
  12. Get-ChildItem -Path C:\Finance | Export-CSV C:\FinanceFiles.csv


  13. 7. Set an Email Auto-Reply
  14. Set-MailboxAutoReplyConfiguration PeterStavrou -AutoReplyState enabled -ExternalAudience all -InternalMessage “Please note, Peter Stavrou is on leave. 

    Please contact our office on 03 9898 0100.

    Thank You” -ExternalMessage “Please note, Peter Stavrou

    Please contact our office on 03 9898 0100.

    Thank You”

    Replace PeterStavrou with the User ID you want to set the auto-reply for.

    Replace Please note, Peter Stavrou is on leave. Please contact our office on 03 9898 0100. Thank You with the auto-reply message you would like to use.
    Please note that </br> is simply used to insert a line break (place text on the next line).


  15. 8. Search All Mailboxes in Exchange and Place Found Emails in Your Mailbox
Get-Mailbox | Search-Mailbox -SearchQuery '[email protected]' -TargetMailbox "PeterStavrou" -TargetFold
er "AdminHotmailEmails" -LogLevel Full

The above example will find all emails that contain [email protected] and will copy them to PeterStavrou‘s Mailbox under the folder AdminHotmailEmails.

Replace [email protected] with the word you would like to search for.

Replace PeterStavrou with the Mailbox ID that you want the emails copied to.

Replace AdminHotmailEmails with the folder name you would like to create in PeterStavrou’s mailbox to copy the emails into.

If you receive an error in Exchange PowerShell when using the search command then type in the below and try again.:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

What are your favorite PowerShell commands and what do they do?

Share Your Thoughts