Frequently used cmdlets

Exchange Server administration forum
Post Reply
Posts: 98
Joined: Sat Sep 26, 2009 9:57 am
Location: India

Frequently used cmdlets

Post by ManU » Tue Jun 14, 2011 5:19 pm


I am hereby updating the cmdlets developed and used for various purposes. I hope to update this thread daily so that everybody have a look for most needy cmdlets.

1. Set-ExecutionPolicy

Enables you to determine which of the following four Windows PowerShell scripts run on your computer

When you first get started with PowerShell, don’t forget to run ‘Set-ExecutionPolicy RemoteSigned’ from the PowerShell prompt. If you try to run a script without doing that first, expect to see a message like the following:

Code: Select all

File <path to file> cannot be loaded because execution of scripts is disabled on this system.  Please see “get-help about_signing” for more details
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

Example:Set-ExecutionPolicy RemoteSigned
This command sets the execution policy to RemoteSigned

2. Find mailbox size of all members in a distribution group
Get-DistributionGroupMember "Group Name" | foreach {Get-MailboxStatistics $_.Name} | select DisplayName,TotalItemSize, database | export-csv c:\temp\test.csv

3. Get-ExchangeCertificate
Use the Get-ExchangeCertificate cmdlet to view certificates in the local certificate store.

Example: Get-ExchangeCertificate
This example returns the properties of a specified certificate in a formatted list.

4. Remove-ExchangeCertificate

This cmdlet is used to remove a certificate from the Exchange environment

Example: Remove-ExchangeCertificate -thumbprint "%THUMBPRINT%"

Removes a certificate with thumbprint named %THUMBPRINT%

5. test-edgesynchronisation

Use the Test-EdgeSynchronization cmdlet to diagnose whether the subscribed Edge Transport servers have a current and accurate synchronization status.

Example: test-edgesynchronisation
This verifies syncronization status of Edge Server with Hub Server

Test-EdgeSynchronization -VerifyRecipient
This verifies the synchronization status of the single recipient

6. List all disconnected mailboxes
To list all disconnected mailboxes in Exchange Management Shell with Display Name and GUID, run the following cmdlet:

Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

7. Mailbox Statistics as a report

The following cmdlet gives a csv file with the following details

get-mailbox | get-mailboxstatistics | export-csv -path c:\exchangestatistics.csv

Note:By default only the first 1000 items are returned. To change the number of items returned, specify the parameter "-ResultSize". To return all items specify "-ResultSize Unlimited"
If there is no data associated with mailboxes included, that will be displayed as warnings.

8. Mailbox size report

The following cmdlet gives a csv file with the following details:

get-mailbox | get-mailboxstatistics | select-object DisplayName,TotalItemSize,StorageLimitStatus,LastLogonTime | export-csv -path c:\userstatistics.csv

Note: The notes are as above for 7

9. Bulk user import
The following cmdlets can be used in Exchange2010 for a bulk user import from a csv file:

Import-CSV C:\users.csv | ForEach-Object -Process {New-Mailbox -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit $_.OU -UserPrincipalName $_.UPN -Alias $_.alias -Database "Name of database" -Password $Password}

Import-CSV C:\users.csv | ForEach-Object -Process {New-Mailbox -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit $_.OU -UserPrincipalName $_.UPN -Alias $_.alias -Database "Name of database" -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}
Microsoft MVP(Exchange Server)
TechNet Forums Profile: ManU

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests