0

我在将一个属性的输出作为逗号分隔值而不是 out-gridview 中的列表时遇到问题。有没有办法将值作为列表而不是单行添加到输出中?

.'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*")

让 $folders.Name 在同一个 out-Gridview 中显示为列表的任何帮助都会很棒。

谢谢

4

1 回答 1

0

您可能正在寻找:

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

这样,您不再使用对象,而是通过将元素与新行连接来手动创建列表。

于 2020-08-13T21:51:46.350 回答