我正在使用的代碼如下
New-Object PSObject -Property @{
Product = $_.Name
Stockcode = $_.Group[0].Stockcode
QuantityCounted = ($_.Group | Measure-Object -Property QuantityCounted -Sum).Sum
}
}| Export-Csv "E:\CSV\test.csv" -NoTypeInformation
標題應按此順序 Product | 股票代碼 | 數量計數

如果有人能指出我正確的方向,那就太棒了,謝謝
uj5u.com熱心網友回復:
默認情況下不會對哈希表進行排序,除非您強制它們:
New-Object PSObject -Property (
[ordered]@{
Product = 1
Stockcode = 2
QuantityCounted = 3
})
此外,除非您運行的是舊版本的 PowerShell:
該
[pscustomobject]型別加速器在PowerShell中添加4.0。
[pscustomobject]@{
Product = 1
Stockcode = 2
QuantityCounted = 3
}
PSCustomObject 是默認排序的,效率更高。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/389926.html
