Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Compare 2 variables -contains

$
0
0

Hi i always find it difficult comparing objects in powershell.

Having 2 variables 

$var1 

user1

user2

user2

And $var2

name        status

user2         1

user3         1

user4         0

I want to compare both variables ans return users that are $var2 that are also in $var1

I tried like:

foreach ($user in $var2) {
  if ( $var1 -contains $user.name  ){
write-host $user
  }
  }

Also

$var2| foreach-object { 
 if ($_.username -notcontains $var1)  
 write-host $var2 }

But i get nothing in any of the queries...

What am i doing wrong?

Thanks



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>