by TPCK1 at 2012-08-23 12:08:22
I’m new to the powershell scripting environment and need a little help.by poshoholic at 2012-08-23 14:02:51
I want to pull all mailboxes from my exchange server but I want to eliminate all shared resources, distribution groups, and generic logins and email addresses like csr123, shop123.
So far this is the code I have - which works but it’s pulling everything on the exchange server:
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress,Company,Department,Office > c:\scripts\mailboxes.txt
They way the script pulls it’s also formatting the results in the following manner:
DisplayName : LastName, FirstName
ServerName : Exchange
PrimarySmtpAddress : email@example.com
Office : Corporate
Instead of the results in the above format I would like it to just go across so it would make it easier to dump into Excel.
Any help would be greatly appreciated - and I apologize ahead of time if I’m posting in the incorrect area or manner.
What you’re asking is simple enough. You want to perform server side filtering either using the parameters on Get-Mailbox or, specifically, using the Filter parameter, so that you don’t get all objects back from the server. You should start by reading help on the Filter parameter for Get-Mailbox.
[script=powershell]Get-Help Get-Mailbox -Parameter Filter[/script]
Regarding your comment about getting it into Excel, have you looked at the Export-Csv cmdlet? That command was designed with this goal in mind. Instead of redirecting the results of your command to a file, pipe the results to Export-Csv. The file you end up with will open up directly in Excel (which is what you are looking for).
[script=powershell]Get-Help Export-Csv -examples[/script]
Also, we have a forum for Exchange PowerShell questions called “PowerShell and Exchange”, so I’m going to move this over there. Note it will appear in both forums after the move and you’ll be able to see all replies in both forums; however, for future posts on Exchange PowerShell that forum would be your best bet. I think I’m answering most of your questions, but if you need further help with the -Filter parameter, you’ll want the moderators of that forum to see your replies.