Compare-Object HR vs AD
hello,
trying out find differences between hr system , ad.
hr uses column personalnumber (employeenumber), jmeno (name) .. , other properties not related ad.
there many accounts in ad not exist in hr, , otherwise.
so, im trying compare property employeenumber (aka personalnumber), exists on hr ..
## hr.csv "personalnumber","jmeno","datumod","datumdo" "101","test1","1-4-2008","1-31-2008" "102","test2","1-4-2008","1-31-2012" "103","test3","1-4-2005","1-31-2008" "104","test4","1-4-2008","" ## ad.csv "employeenumber","name","enabled","homemdb" "101","test1","true","db1" "102","test2","false","" "103","test3","true","db4" "110","test10","true","db3" "111","test11","false",""
$hr = import-csv .\hr.csv $ad = import-csv .\ad.csv $ref = $hr |select *,@{n="employeenumber";e={$_.personalnumber}} compare-object -referenceobject $ref -differenceobject $ad -property employeenumber -includeequal -passthru | sort employeenumber personalnumber : 101 jmeno : test1 datumod : 1-4-2008 datumdo : 1-31-2008 employeenumber : 101 sideindicator : == personalnumber : 102 jmeno : test2 datumod : 1-4-2008 datumdo : 1-31-2012 employeenumber : 102 sideindicator : == personalnumber : 103 jmeno : test3 datumod : 1-4-2005 datumdo : 1-31-2008 employeenumber : 103 sideindicator : == personalnumber : 104 jmeno : test4 datumod : 1-4-2008 datumdo : employeenumber : 104 sideindicator : <= employeenumber : 110 name : test10 enabled : true homemdb : db3 sideindicator : => employeenumber : 111 name : test11 enabled : false homemdb : sideindicator : =>
as u see, items contains data $hr, others $ad (depends on sideindicator). see same properties on items..
like
employeenumber (ad), name (ad), datumod (hr), datumdo (hr),homemdb (ad), sideindicator .. is possible using compare-object cmdlet?
maybe should go creating custom table .. like
foreach ($item in $ad) { $datahr = $ref |?{$_.employeenumber -eq $item.employeenumber} $myobject = new-object psobject -property ([ordered]@{ ad_employeenumber = $item.employeenumber ad_name = $item.name ad_enabled = $item.enabled ad_homemdb = $item.homemdb hr_employeenumber = $datahr.employeenumber hr_name = $datahr.jmeno hr_datumod = $datahr.datumod hr_datumdo = $datahr.datumdo }) $mycol += $myobject } $mycol
ad_employeenumber : 101 ad_name : test1 ad_enabled : true ad_homemdb : db1 hr_employeenumber : 101 hr_name : test1 hr_datumod : 1-4-2008 hr_datumdo : 1-31-2008 ad_employeenumber : 102 ad_name : test2 ad_enabled : false ad_homemdb : hr_employeenumber : 102 hr_name : test2 hr_datumod : 1-4-2008 hr_datumdo : 1-31-2012 ad_employeenumber : 103 ad_name : test3 ad_enabled : true ad_homemdb : db4 hr_employeenumber : 103 hr_name : test3 hr_datumod : 1-4-2005 hr_datumdo : 1-31-2008
and use where-object construct require information need. we talking 5000 accounts in ad.. looping every record in ad find data in hr seems me quite ineffective
reversi!
$users = import-csv hrfile get-aduser -filter * -prop employeenumber| foreach-object{ $enum = $_.employeenumber if ($users | %{$_.personalnumber -eq $enum}) { # employeenumner found } else { # not found } }
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment