我有一个名为test.csv的文件,文件中的数据如下所示:
ServerName,Software
"server1.domain.com","Security Update for Windows Server 2003 (KB890046)"
"server1.domain.com","Security Update for Windows Server 2003 (KB893756)"
"server2.domain.com","Microsoft .NET Framework 3.5 SP1"
"server2.domain.com","Microsoft SQL Server 2005"
"server3.domain.com","Security Update for Windows Server 2003 (KB916281)"
"server3.domain.com","Security Update for Windows Server 2003 (KB917159)"
我想将“ServerName”作为文件名拆分为每个服务器的文件,并包含“软件”列中的数据
我希望输出看起来像这样:
file: server1.domain.com.csv
Security Update for Windows Server 2003 (KB890046)
Security Update for Windows Server 2003 (KB893756)
file: server2.domain.com.csv
Microsoft .NET Framework 3.5 SP1
Microsoft SQL Server 2005"
file: server3.domain.com.csv
Security Update for Windows Server 2003 (KB916281)
Security Update for Windows Server 2003 (KB917159)
我是Powershell的新手,无法解决如何做到这一点。感谢。
答案 0 :(得分:3)
尝试此操作,按ServerName对内容进行分组。 Foreach组选择Software属性并将其导出到具有每个服务器名称的csv文件:
Import-Csv test.csv | Group-Object ServerName | Foreach-Object{
$_.Group | Select-Object Software | Export-Csv "$($_.Name).csv" -NoTypeInformation
}