Link to home
Start Free TrialLog in
Avatar of CiscoAzn
CiscoAznFlag for United States of America

asked on

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

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.
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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.
Avatar of CiscoAzn

ASKER

How would you merge the cmds together? Is there a way to script this all to a .ps1 file?
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.
Script didn't work.
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I apologize for not getting back on this and thank you for your assistance.