We help IT Professionals succeed at work.

Powershell script for list of all users, city, state, and mailbox size

2,936 Views
Last Modified: 2014-01-15
I need one command to run the a list in Excel for all users, city, state, and mailbox size. I can run this from 2 commands but want to know if there is one single powershell cmd that can accomplish this.
Comment
Watch Question

Will SzymkowskiSenior Solution Architect
CERTIFIED EXPERT
Most Valuable Expert 2015
Top Expert 2015

Commented:
You are trying to pull data from 2 different modules activedirectory and Exchange. You can merge the commands together and use the "out-file" command with -append switch to append the results to the same file, but the commands need to be run separate and the results would not be in the respective columns beside them it would be appended at the bottom.

Will.

Author

Commented:
How would you merge the cmds together? Is there a way to script this all to a .ps1 file?
Will SzymkowskiSenior Solution Architect
CERTIFIED EXPERT
Most Valuable Expert 2015
Top Expert 2015

Commented:
Use the following Powershell script below...
Import-module activedirectory
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
Get-ADUser -Filter * -Properties * | Select DisplayName, City, State | Out-File "c:\export.csv" -append
Get-Mailbox -ResultSize "Unlimited" | Get-mailboxStatistics | Select DisplayName, TotalItemSize, TotalDeletedItemSize | Out-File "c:\export-csv" -append

Open in new window

The code above will run each command seprately and it will append the results to the same CSV file.

You need to have Powershell and both Active Directory and Exchange modules/Snapins added to the session in order for this to work. Depeneding on the version of Exchange you are running you might have to change the ADD-PSSnapin line accordingly.

Will.

Author

Commented:
Script didn't work.
Senior Solution Architect
CERTIFIED EXPERT
Most Valuable Expert 2015
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I apologize for not getting back on this and thank you for your assistance.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.