0

In Powershell, I need to create a set of unique strings. Powershell's standard array collection allows for duplicate strings. Powershell's standard hashtable collection allows for unique keys but requires values. How do I create a set in Powershell, a collection that has no duplicate values?

The script I'm running queries SCCM Device Collections. I need a list of all the hosts in a select group of Device Collections. Because a host can be a member of more than one collection, loading the values in an array creates many duplicates. Here's some sample data:

Device Collection 1.
    Server1
    Server2
    Server3
Device Collection 2.
    Server1
Device Collection 3.
    Server3
    Server4
    Server5

What I need:

$host_list = 'Server1','Server2','Server3','Server4','Server5'

What I get with a regular array:

$host_list = 'Server1','Server2','Server3','Server1','Server3','Server4','Server5'

I assume there's a "Set" collection type in .Net that I can use. Can you help me find the right one?

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
Bagheera
  • 1,358
  • 4
  • 22
  • 35

0 Answers0