To understand some of the oddities you see, we need to take a step back and look at the big picture, namely, the PowerShell infrastructure is built on top of: .NET!
Object Equality in .NET
$user1 -eq $user2fails because $user1both $user2are two different objects, although both can represent the same object in Active Directory.
.NET, .
, , [int], , , :
$a = 1
$b = 1
$a.Equals($b)
- , , , , :
$a = New-Object object
$b = New-Object object
$a.Equals($b)
, , $a $b , [object] .
GetHashCode() (, ) Equals() (, ), , , -, - [string] :
$a = "test"
$b = "test"
$a.Equals($b)
ADEntity ( ActiveDirectory) - , , .
PowerShell
, , :
$a1 = @(1;2;3)
$a2 = @(1;2;3)
$a1 -eq $a2
, , PowerShell!
(-eq, -ne, -gt, -like, -match ..) : .
, : $true $false.
( ) , ( ) .
, :
$names = "James","Jane","John"
$prefix = "Ja"
$names -like "$prefix*"
, -like - James Jane.
@(1;2;3) - eq @(1;2;3)
, - , (1 -eq @(1;2;3), 2 -eq @(1;2;3) ..) $true
. Active Directory , , - objectGUID. A GUID .NET - , :
$ones = Get-ADPrincipalGroupMembership one
$seconds = Get-ADPrincipalGroupMembership second
$excl_ones = $ones | ? { $_.objectGUID -notin $seconds.objectGUID }
(, , ..) , , objectSID - .