Tuesday 5 June 2012

Exchange single PowerShell command line tips and tricks


Below are some of the single line PowerShell commands which will help you routine Exchange tasks.

 
To find Deleted Mailboxes from Exchange Server:

Get-MailboxStatistics -Server Exch01| where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate

To Change Primary SMTP for bulk Users:

Import-Csv "C:\Powershell\user.csv" | foreach {
Set-Mailbox $_.alias -PrimarySmtpAddress ("{0}.{1}@contoso.com" -f $_.firstname,$_.lastname) -EmailAddressPolicyEnabled $false }

CSV file format:


Alias,Firstname,Lastname
Test.cloud,Test,Cloud




Provide Full Access Permission on multiple User Mailboxes for any Admin Account:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

-
$csv = import-csv "C:\Powershell\user.csv"
$csv | Foreach {
$Indentity = $_.ID
Add-MailboxPermission -Identity $_.ID -User TestAdmin -AccessRights FullAccess
}

CSV File format:

Id
Test.Cloud



Delete Bulk Exchange Public Folders:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

-
$csv = import-csv "C:\Powershell\Delete_BulkPublicFolder\Public.csv"
$csv | Foreach {
Remove-PublicFolder -id $_.id -confirm:$false
}


CSV file format:


id
\Test4
\Test5
\Test6


Extract Exchange 2007 Active sync users list:

Get-Mailbox -ResultSize:Unlimited | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} |ft identity,devicemodel,devicetype,LastSuccessSync >c:\user.csv


To get Exchange 2007 CAS server Certificate details:

Get-ExchangeCertificate | select thumbprint, issuer, isselfsigned, services, notafter


Remove Certificate:

Remove-ExchangeCertificate -Thumbprint 15de8243s72gchb75h4d8108626674333d013f


ActiveSync policy applies to Bulk Users:

Import-CSV -Path C:\Powershell\iphonepolicy.csv | % {Set-CASMailbox -Identity $_.Alias -ActiveSyncMailboxPolicy (Get-ActiveSyncMailboxPolicy “iPhone Test policy”)}

CSV File Format:
Alias
Test.cloud
Test.active


To Create Bulk External Contacts:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

$csv = import-csv D:\Powershell\Conatcts\Createcontacts3.csv
$csv | % {
new-mailcontact -name $_.name -Firstname $_.firstname -lastname $_.lastname -alias $_.alias -externalemailaddress $_.external -OrganizationalUnit $_.OUpath
Set-MailContact $name -HiddenFromAddressLists $Enabled
}


CSV File format:
name,firstname,lastname,alias,external,Oupath
Test Cloud,Test,Cloud,Test.Cloud,test.cloud@gmail.com, OU=Test,OU=Conatcts,DC=Contoso,DC=com"


To Set multiple DOMAIN CONTRL in Exchange Server:

Set-ExchangeServer -identity Exch01-DomainController dc01.domain.com -StaticDomainControllers ‘dc01.domain.com’,‘dc02.domain.com’ -StaticGlobalCatalogs ‘dc01.domain.com’, dc02.domain.com’-StaticConfigDomainController ‘dc01.domain.com’, ‘dc02.domain.com’




To find Manual quota is defined or not for Bulk users:
Open a .txt file and copy the below command, save the file as .ps1
-------------------------------------------------------------
$CSV = Import-Csv "C:\Powershell\quota.csv"
$csv  | Foreach {
$Indentity = $_.Alias
get-mailbox -Identity $_.Alias | Where {$_.UseDatabaseQuotaDefaults -eq $false}
}
------------------------------------------------------------

CSV Format:
Alias
Test.user
Test.user1

Get Database Quota Result for all Mailbox servers:

Get-MailboxDatabase | Select-Object ServerName,Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota | Sort-Object Name | Export-Csv :\DatabaseLimits.csv –NoTypeInformation


Apply Quota for Bulk Database:

Copy below to TXT file and convert into .PS1
------------------------------------
$csv = import-csv "C:\Powershell\DB\DB.csv"
$csv | Foreach {
Set-MailboxDatabase-Identity $_.DB -IssueWarningQuota 900MB -ProhibitSendQuota 1024MB -ProhibitSendReceiveQuota 8192MB
}
-----------------------------------

CSV Format:
DB
MAIL1\SG1\MBXStore1
MAIL1\SG2\MBXStore2
MAIL1\SG3\MBXStore3

 
ActiveSync policy user list with Policyname and server
Get-CASMailbox -Filter {ActiveSyncMailboxPolicy -eq $ActiveSyncPolicyName} |ft Displayname, ActiveSyncMailboxPolicy, Servername
 
Search by ActiveSync Policy Name
Get-CASMailbox -ResultSize 20000000 | where{$_.activesyncmailboxpolicy -match "ActiveSync Without Device Password Policy"} | ft Displayname >d:\result.csv


Hope this helps.
Expect more!!



4 comments:

  1. :) good to see u on the floor... -Vishal

    ReplyDelete
  2. To export exchange mailbox to outlook PST, a lot of third party applications are available. Stellar Phoenix EDB to PST converter is one such powerful tool. More info. is available here:
    http://edbtopstconverter.stellarservertools.com/

    ReplyDelete