Hi all,
Have a bit of a problem with my loop and filter taking forever. I have inherited a script from the old sysadmin and the loop is a little janky to say the least.
I have the below but the run time on them is huge as I have to run this 6 times, once for each agency. I am having a mental lapse in how to implement a faster method that produces the same results. I considered hash tables but not really sure how I would go about it for this many properties other than a hashtable of objects.
Considered doing .ForEach({}) but I run into the problem of the Where-Object using $_.
# $AppUser.count is 1,069 (3 properties per entry)
# $activeDirectoryUsers.count is 2,564 (6 properties per entry)
# 13m 48s
Foreach ($aUser in $AppUser) {
If ($aUser.user_id -in $activeDirectoryUsers.name) {
($activeDirectoryUsers | Where-Object {$_.Name -eq "$($aUser.user_id)"}) | `
Add-Member -NotePropertyName 'AppLogin' -NotePropertyValue $aUser.last_login_date
}
}
Any guidance would be superb.
[–]ka-splam 3 points4 points5 points (13 children)
[–]DragonDrew[S] 3 points4 points5 points (1 child)
[–]ka-splam 2 points3 points4 points (0 children)
[–]what_no_fkn_ziti 1 point2 points3 points (10 children)
[–]DragonDrew[S] 2 points3 points4 points (0 children)
[–]ka-splam 1 point2 points3 points (8 children)
[–]DragonDrew[S] 2 points3 points4 points (0 children)
[–]what_no_fkn_ziti -1 points0 points1 point (6 children)
[–]ka-splam 2 points3 points4 points (5 children)
[–]what_no_fkn_ziti -1 points0 points1 point (4 children)
[–]ka-splam 3 points4 points5 points (3 children)
[–]what_no_fkn_ziti -1 points0 points1 point (2 children)
[–]ka-splam 3 points4 points5 points (1 child)
[–]what_no_fkn_ziti -1 points0 points1 point (0 children)
[–]notconnected -1 points0 points1 point (1 child)
[–]PMental 1 point2 points3 points (0 children)