参照スクリプト:
スクリプト 1:
$csvList = @()
$csvList += New-Object PSObject -Property @{name="test1";accountname="testuser1";mail="user1@somewhere.com"}
$csvList += New-Object PSObject -Property @{name="test2";accountname="testuser2";mail="user2@somewhere.com"}
$csvList += New-Object PSObject -Property @{name="test3";accountname="testuser3";mail="user3@somewhere.com"}
$csvList += New-Object PSObject -Property @{name="test4";accountname="testuser4";mail="user4@somewhere.com"}
$csvList | Export-Csv c:\temp\testcsv.csv -NoTypeInformation
スクリプト 2 (拡張使用を反映するために編集で追加):
$aTest = @()
for($x=0;$x -le 5;$x++)
{
$aTest += New-Object PSObject -Property @{Name="test$($x)"; `
AccountName="testuser$($x)"; `
Mail="user$($x)@somewhere.com"}
}
$aTest | Export-Csv c:\temp\testcsv.csv -NoTypeInformation
質問:
そのスクリプトは CSV を作成し、必要なすべてのデータを正しい行に含めますが、列の位置を制御する方法がわかりません。name,accountname,mail
Powershellでデータを注文して追加していますが、 mail,name,accountname
. 列の順序を制御するにはどうすればよいですか?
注:エクスポート前にコンテンツのスクリーン ダンプを実行すると$csvList
、順序は既に変更されています。