Solved

Need Help on PowerShell script

Posted on 2011-02-18
5
987 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 71

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this video we show how to create an email address policy 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…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

730 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