如果我正确地解释你的代码,你指的是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"
这一个班轮:
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:\用户\公共\文件\网络钓鱼> DIR |的ForEach-对象{ $名称= $ _(在$名称$ N)命名 的foreach { 导入-CSV $ N |' FOREACH { $发件人+ = $ _。SenderAddress $收件人+ = $ _。RecipientAddress $主题+ = $ _。主题 } } } – LittleBuddha