Solved

Need Help on PowerShell script

Posted on 2011-02-18
5
985 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

831 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