あなたのコードを正しく解釈していれば、配列ではなくcsvファイルの列を参照しています。インポート後に希望のプロパティを選択するだけで十分ですが、新しい短いプロパティ名は[pscustomobject]
で実現できます。
があるとします
> Get-Content first.csv
"othercol","SenderAddress","RecipientAddress","Subject"
"","[email protected]","[email protected]","Overdue invoices"
"","[email protected]","[email protected]","Receipts"
と:
>Get-Content second.csv:
"SenderAddress","RecipientAddress","Subject","othercol"
"[email protected]","[email protected]","Overdue deliveries","xyz"
"[email protected]","[email protected]","Orders","abc"
この1つのライナー:
foreach ($File in (gci *.csv)){Import-Csv $File|Select SenderAddress,Recipientaddress,Subject}
意志出力:
SenderAddress RecipientAddress Subject
------------- ---------------- -------
[email protected] [email protected] Overdue invoices
[email protected] [email protected] Receipts
[email protected] [email protected] Overdue deliveries
[email protected] [email protected] Orders
これより冗長バージョン:
ForEach ($File in (Get-ChildItem *.csv)){
Import-Csv $File | Select-Object SenderAddress,Recipientaddress,Subject |
ForEach-Object{[pscustomobject] @{Sender = $_.SenderAddress
Recipient = $_.Recipientaddress
Subject = $_.Subject}
}
}
は、この出力が得られます。
Sender Recipient Subject
------ --------- -------
[email protected] [email protected] Overdue invoices
[email protected] [email protected] Receipts
[email protected] [email protected] Overdue deliveries
[email protected] [email protected] Orders
プログラミング言語タグを追加し、あなたが –
を試してみました何のサンプルは、あなたが私たちにこれらの配列のコード例を与えることができますしてください? どのようにこれらの3つの配列を一致させることができますか?$ Sender [0]、$ Recipient [0]、$ Subject [0]? – SteloNLD
PS C:公共\ドキュメント\ \ Users \ユーザーフィッシング> DIR |をForEach-Objectに{ $名= $ _ foreachの($名で$ N){ インポート、CSV $ Nを名前| ' のForeach { $。送信者+ = $ _。SenderAddress $受信者+ = $ _。RecipientAddress $件名+ = $ _。件名 } } } – LittleBuddha