CSV into DGV

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 2 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
apowershelluser
Posts: 190
Last visit: Mon Mar 18, 2024 7:13 pm
Answers: 1

CSV into DGV

Post by apowershelluser »

Hi,
I have CSV it contains USERNAME, Manufacturer, Model, hundreds of rows of different Names, Manufacturers and Models. We're looking to quickly few the counts of each model types.

So something similar would be

JohnSmith , HP , 840G8
JaneSmith , Apple , 15 inch iPad Pro
DarringSmith, Dell, 7510

How can I view in a DGV, just the Model and the Counts, so example:
Apple 15 inch iPad Pro 40
HP 840 G8 1500
Dell 7470 1500
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CSV into DGV

Post by jvierra »

Use the "Group-Object" CmdLet to get the counts.
User avatar
apowershelluser
Posts: 190
Last visit: Mon Mar 18, 2024 7:13 pm
Answers: 1

Re: CSV into DGV

Post by apowershelluser »

I did find group-object

but used group-object Model
am getting this
Assets.png
Assets.png (15.04 KiB) Viewed 7111 times
anyway to shorten the code?
  1. import-csv '\\share\assets.csv' | Select-Object Manufacturer, Model, Count | Group-Object Model | ForEach-Object {
  2. [PSCustomObject]@{
  3.  
  4. 'Count' = $_.Count;
  5. 'Model' = $_.Name;
  6. 'Manufacturer' = $_.group.manufacturer | Select-Object -Unique;
  7. }
  8. } | Sort-Object Count -Descending
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CSV into DGV

Post by jvierra »

Start by writing the code correctly.
  1. import-csv '\\share\assets.csv' |
  2.     Group-Object Model,Manufacturer |
  3.     Sort-Object Count -Descending |
  4.     Select-Object Name, Count
User avatar
apowershelluser
Posts: 190
Last visit: Mon Mar 18, 2024 7:13 pm
Answers: 1

Re: CSV into DGV

Post by apowershelluser »

Hi, thanks for the tip
but its not formatted correctly still

note the manufactuer is in the same column as name
Assets.png
Assets.png (9.61 KiB) Viewed 7081 times
and not like this :)
assets2.png
assets2.png (7.23 KiB) Viewed 7081 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CSV into DGV

Post by jvierra »

So. Split the Name into two fields using computed properties in the last select-object statement.
User avatar
apowershelluser
Posts: 190
Last visit: Mon Mar 18, 2024 7:13 pm
Answers: 1

Re: CSV into DGV

Post by apowershelluser »

Got it! Thanks so much
This topic is 2 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