powershell - PSCustomObject out-gridview 格式不正确
问题描述
我在将一个属性的输出作为逗号分隔值而不是 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 中显示为列表的任何帮助都会很棒。
谢谢
解决方案
您可能正在寻找:
Name = $($folders.Name -join [Environment]::Newline)
这样,您不再使用对象,而是通过将元素与新行连接来手动创建列表。
推荐阅读
- python - 如何使用 pyside2 在 Qtableview 中显示(和格式化)日期时间数据
- javascript - 如何从请求中返回此函数中的 var?
- azure-devops - 如何从 Power bi 中的 Azure DevOps 查询工作项的状态更改
- angular - CORS 策略已阻止对 XMLHttpRequest 的访问。请求的资源上不存在“Access-Control-Allow-Origin”标头
- apache-nifi - 如何配置 PutFile 使其按 24 小时计划运行,但运行时间与传入流文件的数量一样多
- svelte - 使用附加的 svelte 组件并在相同的 Javascript 上下文中创建窗口
- sql - 使用 LIKE 运算符或更好的方法连接 2 个表的最佳实践
- python - Flask 自定义装饰器
- ios - 在获取数据 Firebase / Swift 之前加载的 TableView
- r - R Markdown:在“参考”部分之后放置一个附录?