0

As part of a larger script i'm making a refrencelist of servernames which should contain all servers in our infrastructure. To do this i have 4 arrays with servernames sourced from diffrent systems (AD, SQL etc) which i planned to join together using:

$Refrencelist = $var1.Name + $var2.Name + $var3.Name + $var4.Name | Select-Object -Unique 

Altough this mostly does the job i'm still seeing some duplicates in the resultning list and from what i can gather it's because the MemberType of the .Name property in the SQL $var is Property while the MemberType of Name in the other varibales is NoteProperty.

Is this what's causing the duplicates? If so, how do i solve this?

Thanks.

Notumlord
  • 33
  • 5

1 Answers1

0

You could try to combine the objects to an array and use -Unique on the name Property:

$referenceList = @($var1, $var2, $var3, $var4)
$uniqueList = $referenceList | select -Unique {$_.Name}
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • Sorry for late reply. That didn´t work unfortently the result is this which doesnt seem to be in a format i can work with for further filtering and export. $_.Name ------- {server105, server23, server145, server103...} {server12, server11, server12, server13...} {server7, server8, server9, server10...} Sorry for not fornatting properly, can´t get it to recognise the above lines as code for some reason. – Notumlord Mar 28 '16 at 16:45