0

I am having an issue with the output from one property as a comma separated value instead of a list in the out-gridview. Is there a way to have a value be added to the output as a list instead of a single line?

.'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -Auto -AllowClobber

do {
Write-Host
Write-Host
Write-Host
$name = Read-Host "What is the user's first name or letter?"
Write-Host
Write-Host
Write-Host
$list = Get-ADUser -Filter * | ? {$_.SamAccountName -match $name} |
 select @{N="Highlight a User & Press Ctrl+C then Ctrl+V"; E={$_.SamAccountName}} |
 sort SamAccountName |
 Out-String
Write-Host -ForegroundColor Green $list

$box = Read-Host "Copy and paste the mailbox you want to see?"
$user = $box


$mailbox= Get-Mailbox -Identity $user  | Get-MailboxStatistics |
    Sort totalitemsize -desc | 
    select @{Name="User"; Expression={$_.DisplayName}},
    @{Expression={"{0:N2}" -f($_.TotalItemSize.Value.ToMb()/1024)};label=”Mailbox Size in GB”},
    @{Expression={"{0:N0}" -f($_.TotalItemSize.Value.ToMb())};label=”Mailbox Size in MB”},
    @{Name="Message Count"; Expression={"{0:N0}" -f($_.itemcount)}},
    @{Name="Database"; Expression={$_.DatabaseName}}


$folders= Get-MailboxFolderStatistics $user |
    ? {$_.ItemsInFolder -gt 0} |
    Sort ItemsInFolder -Descending |
    Select Name,
    @{N="Items in Folder"; E={"{0:N0}" -f($_.ItemsInFolder)}},
    @{N=”Folder Size in MB”;E={"{0:N0}" -f($_.FolderSize.ToMb())}}

 
$object= [PSCustomObject]@{
    
    User =                   $mailbox.'User'
    'Mailbox Size in MB'=    $mailbox.'Mailbox Size in MB'
    'Message Count' =        $mailbox.'Message Count'
    Database =               $mailbox.Database
    Name =                   $folders.Name 

}

$object | Out-GridView

   
Write-Host
Write-Host
Write-Host
 $runagain = Read-Host "Would you like to get another user's folder size?" | Out-String
Write-Host
Write-Host  

    }


while($runagain -like "y*")

Any help to get the $folders.Name to show as a list within the same out-Gridview would be great.

Thank you

vnavna
  • 63
  • 1
  • 1
  • 5

1 Answers1

0

You're probably looking for:

Name =                   $($folders.Name -join [Environment]::Newline)

This way you are not using an object anymore but are manually creating a list by joining the elements with a new line.

hcm
  • 922
  • 3
  • 10
  • 1
    Just as an aside (I haven't read the question): There's no need for `$(...)` in your hash-table entry definition. `$(...)` in this context is only ever needed _situationally_ in _Windows PowerShell_, due to [this bug](https://github.com/PowerShell/PowerShell/issues/6970), which has been fixed in PowerShell _Core_. – mklement0 Aug 13 '20 at 22:11
  • Thanks, what you have does create the list now but as only as one cell in the output. I was hoping that the new Name column would have a separate row for each value as well. – vnavna Aug 14 '20 at 17:15