Creating mutiple tables from one

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Locked
User avatar
sekou2331
Posts: 221
Joined: Wed Aug 15, 2012 6:07 am

Creating mutiple tables from one

Post by sekou2331 » Fri Jun 16, 2017 4:49 pm

I have table that I want to make into separate tables. Basically I want to choose what's in a column in a table and make a new table with it. Please see the below.

Code: Select all

Hear1 Header2 Header3
aaa bbb ccc
aaa bbb ccc
111 222 333
111 222 333


Hear1 Header2 Header3
aaa bbb ccc
aaa bbb ccc


Hear1 Header2 Header3
111 222 333
111 222 333

User avatar
jvierra
Posts: 11363
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Creating mutiple tables from one

Post by jvierra » Fri Jun 16, 2017 5:09 pm

I don't think we can understand what you are asking.

Where is this table? PowerShell does not have tables. Perhaps you mean a CSV?

User avatar
sekou2331
Posts: 221
Joined: Wed Aug 15, 2012 6:07 am

Re: Creating mutiple tables from one

Post by sekou2331 » Fri Jun 16, 2017 5:57 pm

Sorry. Correct it is a csv. I want to keep the headers. But I want to separate it by what's in one of the columns

User avatar
jvierra
Posts: 11363
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Creating mutiple tables from one

Post by jvierra » Fri Jun 16, 2017 6:16 pm

Import-Csv file.csv | select col1, col2

Basic PowerShell property selection will do this.'

User avatar
sekou2331
Posts: 221
Joined: Wed Aug 15, 2012 6:07 am

Re: Creating mutiple tables from one

Post by sekou2331 » Sat Jun 17, 2017 2:20 pm

I want to parse a CSV and then add it to different CSV's after the name of the Porcessname please see the code and part of the output. I can use Group-object to separate all the processes I just cant output each separately.

Code: Select all

Get-Process | Group-Object ProcessName|%{$_.Group | select ProcessName, ID | Format-Table}

Code: Select all

chrome.csv
ProcessName Id
chrome 2016
chrome 5436
chrome 5976
chrome 7740
chrome 9732
chrome 9808

MicrosoftEdgeCP.csv
ProcessName Id
MicrosoftEdgeCP 3364
MicrosoftEdgeCP 7140
MicrosoftEdgeCP 7856
MicrosoftEdgeCP 8340
MicrosoftEdgeCP 10372

User avatar
jvierra
Posts: 11363
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Creating mutiple tables from one

Post by jvierra » Sat Jun 17, 2017 2:56 pm

You could have figured this out. You were one step away.

Code: Select all

Get-Process |
Group-Object ProcessName |
ForEach-Object{
$name = $_.Name
$_.Group | Select-Object ProcessName, ID | Export-Csv $name.csv
}

Locked