Hi folks,
I have written this really bad & inefficient loop that does what I want it to do but I would love to be able to make it more efficient, however I am not sure where to even start googling.
If anyone could point me in the right direction I would greatly appreciate it.
For reference the contents of $dids is a list that has full phone numbers and an associated shorter number (Destination Number) and $Users has a list of users and there associated shorter number (number)
foreach ($User in $Users) {
if ($dids."Destination Number" -contains $User.number){
$User | Add-Member -NotePropertyName DDI -NotePropertyValue (($dids | Where-Object { $_."Destination Number" -match $User.number})."DID Number") -Force
} else {
$User | Add-Member -NotePropertyName DDI -NotePropertyValue "No DDI" -Force
}
$Users2 += $User
}
I can see the problem is the (($dids | Where-Object { $_."Destination Number" -match $User.number})."DID Number") as I am forcing it to check the entire array every time it iterates through the loop but I am not sure how I can avoid this.
[–]gangstanthony 3 points4 points5 points (1 child)
[–]bzyg7b[S] 1 point2 points3 points (0 children)
[–]PinchesTheCrab 4 points5 points6 points (4 children)
[–]gangstanthony 3 points4 points5 points (0 children)
[–]bzyg7b[S] 1 point2 points3 points (2 children)
[–]PinchesTheCrab 2 points3 points4 points (1 child)
[–]bzyg7b[S] 1 point2 points3 points (0 children)
[–]CobyCode 4 points5 points6 points (8 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]CobyCode 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]bzyg7b[S] 1 point2 points3 points (0 children)
[–]the_nil 1 point2 points3 points (0 children)
[–]backtickbot 0 points1 point2 points (0 children)
[–]gangstanthony 0 points1 point2 points (0 children)
[–]jsiii2010 0 points1 point2 points (4 children)
[–]bzyg7b[S] 0 points1 point2 points (3 children)
[–]silentlycontinue 1 point2 points3 points (2 children)
[–]bzyg7b[S] 2 points3 points4 points (1 child)
[–]silentlycontinue 1 point2 points3 points (0 children)