Hi All,
I have 2 variables $a and $b, both are set of arrays, but $a has values of 3 column data let’s say name, id, salary, and $b just 1 array of data.
Now, I want to run a command to find out whether $a contains $b and if it contains i want to know the ID of the matching Name, how is that possible?
Compare-Object works for a different usecase, like differential comparison, but in my usecase, the requirement was basically to trigger an action if, name of $a matches $b, so Compare-Object does not actually do the job for me in this use-case.
And for this task you can use Compare-Object. With the parameters -IncludeEqual, -ExcludeDifferent and -PassThru you can get the list of Elements contained in both input arrays.
Okay, now i get it, maybe i need to think of how can i process the outputs i receive using this cmdlet, for ex: compare-object -referenceObject $a -differenceObject $b -includeEqual ?
Your description is very abstract. You may make it more specific. Can you share some sample input data (sanitized from sensitive infromation and formatted as code)?
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
$Matches is a built in variable of PowerShell and should not be used by you for something else.
Just out of curiousity … what’s the advantage of your output over the plain table? If you don’t want the EMP_ID and the SideIndicator you use a Select-Object
So, the need here is to move only the matching userids of $b in $a to a different OU based on their LEVEL, so i am running an if else condition after the compare-object cmdlet, like if($a.level -like “IN1”){MOve user}