Solved

Need Help on PowerShell script

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

691 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