Exchange Query

Hi,

I need an exchange script that will give me the all users in which their email is NOT being forwarded, as well as users who are being Stored and Forwarded
LVL 1
Methodman85Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Adam BrownConnect With a Mentor Sr Solutions ArchitectCommented:
This should do it and output the results to a couple CSV files. It will include some system mailboxes as well, though.
get-mailbox | where {$_.forwardingaddress -like $null} | select primarysmtpaddress,samaccountname,displayname | export-csv C:\noforward.csv
get-mailbox | where {$_.delivertomailboxandforward -notlike $false} | select primarysmtpaddress,samaccountname,displayname,forwardingaddress | export-csv C:\storeandforward.csv

Open in new window

0
 
Methodman85Author Commented:
awesome thank you!
one more thing, I tried to add the users department in the mix, but the field is blank on the CSV file, perhaps I have the wrong name for the department attribute.
0
 
Adam BrownSr Solutions ArchitectCommented:
The department attribute isn't returned by the get-mailbox command, unfortunately. It gets more complex when you want to pull attributes not returned by the get-mailbox cmdlet.
0
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
More complex is right. It'd go like this:
Get-Mailbox -Filter { ForwardingAddress -eq $Null } | Select-Object PrimarySmtpAddress, 
    SamAccountName, DisplayName,
    @{n='Department';e={ (Get-User $_.DistinguishedName).Department }} | 
  Export-Csv C:\noforward.csv -NoTypeInformation

Open in new window

Subject to testing, because I haven't done that.

Chris
0
 
Methodman85Author Commented:
Thank you both!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.