【问题标题】:Combining the variable and the result of Get-MailboxStatistics to select-object and export to CSV format结合变量和 Get-MailboxStatistics 的结果来选择对象并导出为 CSV 格式
【发布时间】:2023-02-15 15:21:00
【问题描述】:

如果我使用 powershell 脚本,它将在控制台上显示正确的结果。

$fileName = 'temp.csv'
$csv = import-csv($fileName)

foreach($item in $csv){
Get-MailboxStatistics $item.name |
Select-Object DisplayName,@{name="depart";expression={$item.dept}},@{name="mail";expression={$item.name}},itemcount,@{name="TotalItemSize (MB)"; expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},lastlogontime
}

但是如果我对文件使用 export-csv,我会得到错误的结果。 “出发”和“邮件”列将是文件的内容。

$fileName = 'temp.csv'
$csv = import-csv($fileName)

$resoult = foreach($item in $csv){
Get-MailboxStatistics $item.name |
Select-Object DisplayName,@{name="depart";expression={$item.dept}},@{name="mail";expression={$item.name}},itemcount,@{name="TotalItemSize (MB)"; expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},lastlogontime
}

$result | export-csv show.csv

为什么这些结果不同?

我使用不同的方法来显示结果。

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    ㅇㄹㄹㄴㅁㄹㅁㄹㄹㄴㅁㅁㄴㅁㅇㅇㄹㄹㅇㅇㄴㅁㅁㄴㄴㅇㅇㄹㄹㅁㄴㄹㄴㄴㅁㅇㄴㅁㅇㅇㅇㅇㄹㄹㄹㄹㄹㄹㄴㅁ

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 2012-08-05
      • 1970-01-01
      • 2018-02-04
      相关资源
      最近更新 更多