Solved

Need Help on PowerShell script

Posted on 2011-02-18
5
983 Views
Last Modified: 2012-05-11
This is the script which I use to export the list of users with 2 GB+ mailbox size. Currently it prints the mailbox size in KB. Is there a way I can print the value in GB? I run this against Exchange 2003 Servers.
Thanks in advance.

$serverlist = "server.txt"
foreach ($server in Get-Content $serverlist) {
  Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $Server -Filter "size>=2097152" | `
  sort-object -desc ServerName | `
  select-object MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size,Totalitems,DeletedMessageSizeExtended,LastLoggedOnUserAccount,DateDiscoveredAbsentInDS | `
  Export-Csv -noType -Path Mailboxlist.csv
}

Open in new window

0
Comment
Question by:Subsun
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
imaki06 earned 250 total points
ID: 34924702
Try to change line 5 to:

select-object MailboxDisplayName,ServerName,StorageGroupName,StoreName, @{Name="SizeInGb";Expression={$_.Size / 1Gb}},Totalitems,DeletedMessageSizeExtended,LastLoggedOnUserAccount,DateDiscoveredAbsentInDS | `
0
 
LVL 40

Author Comment

by:Subsun
ID: 34924850
Thanks it works!!.. I need one more help, when i run this script i am not able to append the date to csv file, I need to create separate files for each server. Is there anything can be done to get the data for multiple servers in same CSV file?
0
 
LVL 70

Assisted Solution

by:Chris Dent
Chris Dent earned 250 total points
ID: 34924892

Avoid "foreach ($this in $that)", use ForEach-Object instead and pipe to CSV at the very end:
Get-Content "server.txt" | ForEach-Object {
  Get-Wmiobject Exchange_Mailbox -Namespace root\MicrosoftExchangeV2 -Computer $_ -Filter "size>=2097152" | `
    Sort-Object -desc ServerName | `
    Select-Object MailboxDisplayName, ServerName, StorageGroupName, StoreName, Size, Totalitems, 
      DeletedMessageSizeExtended, LastLoggedOnUserAccount, DateDiscoveredAbsentInDS
} |  Export-Csv Mailboxlist.csv  -NoTypeInformation

Open in new window

Chris
0
 
LVL 3

Expert Comment

by:imaki06
ID: 34924901
I am not sure how to do this, but this might work:
change export-csv to ConvertTo-CSV
Line 6: ConvertTo-CSV -NoTypeInformation

And then run the script from commandline using redirection:

c:\> myscriptname > Mailboxlist.csv
0
 
LVL 40

Author Closing Comment

by:Subsun
ID: 34924971
Thank you so much for the fast response!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now