Creating mutiple tables from one

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Creating mutiple tables from one

Post by sekou2331 »

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.
  1. Hear1   Header2 Header3
  2. aaa bbb ccc
  3. aaa bbb ccc
  4. 111 222 333
  5. 111 222 333
  6.        
  7.        
  8. Hear1   Header2 Header3
  9. aaa bbb ccc
  10. aaa bbb ccc
  11.        
  12.        
  13. Hear1   Header2 Header3
  14. 111 222 333
  15. 111 222 333
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating mutiple tables from one

Post by jvierra »

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: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Creating mutiple tables from one

Post by sekou2331 »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating mutiple tables from one

Post by jvierra »

Import-Csv file.csv | select col1, col2

Basic PowerShell property selection will do this.'
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Creating mutiple tables from one

Post by sekou2331 »

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.

  1. Get-Process | Group-Object ProcessName|%{$_.Group | select ProcessName, ID | Format-Table}
  1. chrome.csv
  2. ProcessName Id
  3. chrome  2016
  4. chrome  5436
  5. chrome  5976
  6. chrome  7740
  7. chrome  9732
  8. chrome  9808
  9.  
  10. MicrosoftEdgeCP.csv
  11. ProcessName Id
  12. MicrosoftEdgeCP 3364
  13. MicrosoftEdgeCP 7140
  14. MicrosoftEdgeCP 7856
  15. MicrosoftEdgeCP 8340
  16. MicrosoftEdgeCP 10372
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating mutiple tables from one

Post by jvierra »

You could have figured this out. You were one step away.
  1. Get-Process |
  2.     Group-Object ProcessName |
  3.     ForEach-Object{
  4.         $name = $_.Name
  5.         $_.Group | Select-Object ProcessName, ID | Export-Csv $name.csv
  6.     }
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked