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: 237
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.
  1. Hear1   Header2 Header3
  2.  
  3. aaa bbb ccc
  4.  
  5. aaa bbb ccc
  6.  
  7. 111 222 333
  8.  
  9. 111 222 333
  10.  
  11.        
  12.  
  13.        
  14.  
  15. Hear1   Header2 Header3
  16.  
  17. aaa bbb ccc
  18.  
  19. aaa bbb ccc
  20.  
  21.        
  22.  
  23.        
  24.  
  25. Hear1   Header2 Header3
  26.  
  27. 111 222 333
  28.  
  29. 111 222 333

User avatar
jvierra
Posts: 11550
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: 237
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: 11550
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: 237
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.

  1. Get-Process | Group-Object ProcessName|%{$_.Group | select ProcessName, ID | Format-Table}
  1. chrome.csv
  2.  
  3. ProcessName Id
  4.  
  5. chrome  2016
  6.  
  7. chrome  5436
  8.  
  9. chrome  5976
  10.  
  11. chrome  7740
  12.  
  13. chrome  9732
  14.  
  15. chrome  9808
  16.  
  17.  
  18.  
  19. MicrosoftEdgeCP.csv
  20.  
  21. ProcessName Id
  22.  
  23. MicrosoftEdgeCP 3364
  24.  
  25. MicrosoftEdgeCP 7140
  26.  
  27. MicrosoftEdgeCP 7856
  28.  
  29. MicrosoftEdgeCP 8340
  30.  
  31. MicrosoftEdgeCP 10372

User avatar
jvierra
Posts: 11550
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.
  1. Get-Process |
  2.  
  3.     Group-Object ProcessName |
  4.  
  5.     ForEach-Object{
  6.  
  7.         $name = $_.Name
  8.  
  9.         $_.Group | Select-Object ProcessName, ID | Export-Csv $name.csv
  10.  
  11.     }

Locked