Wednesday, December 12, 2012

Most useful Powershell Commands for Exchange

To track emails whether it is delivered or not

1) Get-MessageTrackingLog -Recipients yourmailid@yourdomain.com -sender mailID2@xyz.com | fl *time*,*subject*

If you want to input the sender and recipient you can use the below command
2) Get-MessageTrackingLog  -sender (read-host "Sender") -Recipients (read-host "Recepient")| fl *time*,*subject*

Atleast Sender name or  recipient name anyone should be there to get the result. If you want to get all Senders or all recipient don’t give any inputs just hit enter in the prompt

3) Get the list of   SMTP addresses
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} |Export-csv Addresslist.csv
This will generate the list of all user details with their primary and secondary SMTP address and import to a csv file


4) get the list of Active Directory users who haven’t updated their Phone numbers
 
get-user -resultsize Unlimited |Where {$_.mobilePhone.length  -lt 8 -and $_.Phone.length -lt 8 -and $_.SamaccountName -like "U*"} |select Name,SamaccountName,MobilePhone,Phone |export-csv E:\MissingNumbers.csv –NoTypeInformation

5) Get the List of all email address of users to a powershell.
This script  can also used to get the complete list of secondary email addressess  or to  export Primary and secondary email IDs to csv


Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,@{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object {$_ -LIKE "SMTP:*"}}} | Sort | Export-Csv E:\Sachin\SecEmail.csv



No comments:

Post a Comment