3

I have a file called test.csv, Data in the file is looking like this:

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)"

I want to split it into files for each server using "ServerName" as file name and containing the data from the "Software" column

I would like the output to look like this:

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)

I'm new to Powershell and can't work out how to do it. Thanks.

1 Answer 1

3

Try this, group the content by ServerName. Foreach group select the Software property and export it to a csv file with a name of each server:

Import-Csv test.csv | Group-Object ServerName | Foreach-Object{
    $_.Group | Select-Object Software | Export-Csv "$($_.Name).csv" -NoTypeInformation
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, consider marking it as answered in case it gives you what you need.
Thanks alot Shay! Working Great! Marked as Answered
@user978511, you have similar user names :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.