[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 993
  • Last Modified:

Need Help on PowerShell script

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
Subsun
Asked:
Subsun
  • 2
  • 2
2 Solutions
 
imaki06Commented:
Try to change line 5 to:

select-object MailboxDisplayName,ServerName,StorageGroupName,StoreName, @{Name="SizeInGb";Expression={$_.Size / 1Gb}},Totalitems,DeletedMessageSizeExtended,LastLoggedOnUserAccount,DateDiscoveredAbsentInDS | `
0
 
SubsunAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
imaki06Commented:
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
 
SubsunAuthor Commented:
Thank you so much for the fast response!!
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now