Powershell script to read each mailbox attribute

Status
Not open for further replies.
A

AndreThompson



Hi

I need a Powershell script that will enable me to enumerate each mailbox and retrieve specific attributes into a variable.

Thanks.
 
L

lazyadminhere



The command is: Get-Mailbox | FL

Let me know if it works!
 
A

Amit Tank [MVP]



To save into variable you can use this...

$MBx = Get-Mailbox -ResultSize Unlimited

Attribute of all mailboxes are stored into $MBx array. You can retrive various values like...

- All mailboxes: $MBx | FL

- First Mailbox: $MBx[0]

- 3rd Mailbox: $MBx[2]

- Export it into a CSV file: $MBx | Export-CSV Mailboxes.csv

etc...

Let us know if you want to perform any specific activity or need specific result...


Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration | MCITP: EMA | MCSA: M
Blog: http://ExchangeShare.WordPress.com | User Group: http://MUC-UG.org.in
 
A

AndreThompson



Thanks Amit.

What I need to do is for each mailbox, get the First Name, Last Name, E-mail address, and CustomAttribute1 and it as a record (row) in a database table.
 
A

Amit Tank [MVP]



Powershell can export these values into a CSV file with below cmdlet...

Get-Mailbox -ResultSize Unlimited | Select FirstName, LastName, PrimarySmtpAddress, CustomAttribute1 | Export-CSV Record.csv

Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration | MCITP: EMA | MCSA: M
Blog: http://ExchangeShare.WordPress.com | User Group: http://MUC-UG.org.in
 
A

AndreThompson

I won't be exporting it to a CSV file - I will be doing it on the fly - I will be inserting straight into a SQL Server database.
 
A

Amit Tank [MVP]



I am not sure how to insert into SQL, perhaps you know it...

In that case just remove | Export-CS Record.csv from the command and pipe the output of this cmdlet to your powershell cmdlet to import into SQL...

Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration | MCITP: EMA | MCSA: M
Blog: http://ExchangeShare.WordPress.com | User Group: http://MUC-UG.org.in
 
A

AndreThompson



Unfortunately, I cannot pipe into SQL - you have to use Transact SQL Statements.

Hmm - I gues I can try making a cmdlet for it - interesting.
 
A

Amit Tank [MVP]



Sounds good... It would be appreciated if you can share your findings ant that will be helpful for others who want to export the things from Exchange and import it into SQL DB... :)

Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration | MCITP: EMA | MCSA: M
Blog: http://ExchangeShare.WordPress.com | User Group: http://MUC-UG.org.in
 
Status
Not open for further replies.
Top