If I have an array:
1 1 1 2 2 3 4 4 4 4 5 5
How can I use Powershell to tell me how many of each element there are in that array?
To be a little more clear, I should have a separate count for each array element:
Element:Count
1:3
2:2
3:1
4:4
5:2
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
Group-Objectcmdlet:If you want a hashtable for the items and their counts you just need a little
ForEach-Objectafter it: