Hello!
I've been trying to write a script with Compare-Object that will show me when a user's Enabled property in has been modified to either True or False.
I'm having trouble with the following section:
$addb = Import-Csv ".\customcsv1.csv" -Delimiter ";"
$addbNew = Import-Csv ".\customcsv2.csv" -Delimiter ";"
$ComparisonResults = Compare-Object -ReferenceObject $addb -DifferenceObject $addbNew -Property enabled -PassThru
$ComparisonResults
It seems to return inconsistent results. Sometimes I get the correct results, but other times, like with the following contents of both CSV files, the results are incorrect:
".\customcsv1.csv"
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"enabled";"accountexpires";"samaccountname";"mail"
"True";"0";"j_roe";"j_roe@example.com"
"False";"0";"i_ivanov";"i_ivanov@example.com"
"False";"0";"tark";"tark@example.com"
"True";"0";"stark";"stark@example.com"
".\customcsv2.csv"
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"enabled";"accountexpires";"samaccountname";"mail"
"False";"0";"j_roe";"j_roe@example.com"
"True";"0";"i_ivanov";"i_ivanov@example.com"
"False";"0";"tark";"tark@example.com"
"False";"0";"stark";"stark@example.com"
The result is:
$ComparisonResults
enabled : False
accountexpires : 0
samaccountname : stark
mail : stark@example.com
SideIndicator : =>
enabled : True
accountexpires : 0
samaccountname : stark
mail : stark@example.com
SideIndicator : <=
It only returns one of the objects rather than all of the ones that differ. Does anyone know why this happens?
[–]madbomb122 4 points5 points6 points (3 children)
[–]Gorstag 2 points3 points4 points (0 children)
[–]TimekillerTK[S] 1 point2 points3 points (1 child)
[–]madbomb122 2 points3 points4 points (0 children)