Hello,
Im having trouble to find a bug in my code. I want to see daily changes how computers are created / deleted in our AD.
Looks like, if I create small CSV with few computers, I get what I want.
When I create CSV with 4k+ entries, the result is somehow bugged.
There is my code
$before = Import-csv 'D:\SCRIPTS\PS1\Testing\CSV\before.csv'
$after = Import-Csv 'D:\SCRIPTS\PS1\Testing\CSV\after.csv'
## All changes
$compare = Compare-Object -ReferenceObject $after -DifferenceObject $before -Property OUPath -PassThru -IncludeEqual
$result = $compare |
select name,OUPath,@{n="SideIndicator";e={switch($_.SideIndicator){"<="{"IN"}"=>"{"OUT"}"=="{"=="}}}}|
?{$_.SideIndicator -ne "=="}
$body += "<b><font color=darkblue>All changes </font><b><br>"
$body += ($result |ConvertTo-Html)
## New computers
$new = $result |group name |?{$_.count -eq "1"} |select -ExpandProperty group |?{$_.Sideindicator -eq "IN"}
$body += "<br>"
$body += "<b><font color=green>New computers </font><b><br>"
$body += ($new |ConvertTo-Html)
## Deleted computers
$removed = $result |group name |?{$_.count -eq "1"} |select -ExpandProperty group |?{$_.Sideindicator -eq "OUT"}
$body += "<br>"
$body += "<b><font color=red>Removed computers </font><b><br>"
$body += ($removed |ConvertTo-Html)
## OU Changes
$Oumoves = $($differences = $result |group name |?{$_.count -gt "1"}
foreach ($list in $differences){
$list| select -ExpandProperty group })
$body += "<br>"
$body += "<b><font color=orange> OU changes </font><b><br>"
$body += ($OUmoves |ConvertTo-Html)
Send-MailMessage @messageParameters -body $body -subject "Subject" -BodyAsHtml
and sample CSV $before + $after
$before
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADComputer
"name","OUPath"
"N050A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N051A0001","OU=L4,OU=PCs,DC=contoso,DC=com"
"N051A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N051A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"n053a0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0004","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0005","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0004","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0005","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0006","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0007","OU=L3,OU=PCs,DC=contoso,DC=com"
"N057A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N057A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N057A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
$after
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADComputer
"name","OUPath"
"N050A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N051A0001","OU=L4,OU=PCs,DC=contoso,DC=com"
"N051A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N051A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0002","OU=L3,OU=PCs,DC=contoso,DC=com"
"N052A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"n053a0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0003","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0004","OU=L3,OU=PCs,DC=contoso,DC=com"
"N053A0005","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0001","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0002","OU=L5,OU=PCs,DC=contoso,DC=com"
"N054A0003","OU=L0,OU=PCs,DC=contoso,DC=com"
"N054A0004","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0005","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0006","OU=L3,OU=PCs,DC=contoso,DC=com"
"N054A0007","OU=L3,OU=PCs,DC=contoso,DC=com"
"N055A0001","OU=L4,OU=PCs,DC=contoso,DC=com"
So far so good.
![]()
Problem is, when the CSV contain large number of entries (4500+).
Identical CSV files (just containing more computers) and I made the same changes in after.csv (added n055, removed n057 ..)
The output now is NONSENSE
![]()
Any ideas?