Hi All
I am having an issue with the script below which gives me the results im after for about 100 rows but then it exports incorrect values.
I am trying to compare my CSV which contains GroupName, Description, Managedby against AD and export 'Matched' expressions for matched results, Failed for not matched results and export AD's description and Manager so I can identify the issues.
Please help :)
########################################################################################################## # # # This script imports a spread sheet and checks each row for details and out puts the results # # # ########################################################################################################## #$csv = import-csv C:\PS\import\ESP_Final_Pre_Valuation_testing.csv $csv = import-csv C:\PS\import\ESP_Final_Pre_Valuation.csv foreach ($row in $csv) { $adgroup = get-adgroup $row.groupname -Properties description | select description $adgroup.managedby = (get-aduser -identity $adgroup.managedby) | select name try{ #Searches AD for the group name from the CSV if (get-adgroup $row.groupname){ Write-Host -ForegroundColor cyan "Group"$($row.groupname)"has been found" $row.NameCheck = 'Matched' } else { Write-Host -ForegroundColor red "Group"$($row.groupname)"could not be found" $row.NameCheck = 'Failed' } # Compares AD's group description against the description in the CSV if (Compare-Object $adgroup.description $row.Description) { Write-host -ForegroundColor red "Group"$($row.groupname)"description doesnt match" $row.DescriptionCheck = 'Failed' $row.addescription = $adgroup.description } else { Write-Host -ForegroundColor green "Group"$($row.groupname)"has a matching Description" $row.DescriptionCheck = 'Matched' $row.addescription = $null } # Compares AD's group managedby against the one in the CSV if (Compare-Object ($adgroup.managedby).name $row.managedby) { Write-Host -ForegroundColor red "Group"$($row.groupname)"owner doesnt match" $row.ManagedbyCheck = 'Failed' $row.admanagedby = $adgroup.managedby } else { Write-host -ForegroundColor green "Group"$($row.groupname)"has a matching owner" $row.ManagedbyCheck = 'Matched' } #Exports the above results to a CSV $row | select * | export-csv C:\PS\Exports\ESP_Final_Validation.csv -Append -NoTypeInformation $row.admanagedby = $null $row.addescription = $null } catch{} finally{} }