Home Forums Programming Powershell Remove items from an array based on another array RE: Remove items from an array based on another array

  • Your way did work with a single entry in $Remove. When I added a second entry, neither was removed??

    Weird.

    I was also curious as to why you used a for ... i-- ...next, instead of for ... i++ ... next approach?

    I didn't investigate further since I already had a working solution.

    I wondered if Powershell could "remember" which values it had already looked up in the $Remove list, so that the next time it encountered one already known to be removed, it wouldn't scan the list again. (I think I read somewhere that it can use the equivalent of indexes on sorted data -- don't quote me on that).

    It's taking ~4-5 secs to process the 13K records.

    So, if I add the desired records to [Array]$FinalList, it takes 15 seconds to pass the array to out-file and write it to disk.

    If I instead create a [string]$FinalList, assembling the string takes longer (10-11 seconds), but the out-file is 2 seconds.

    And before you ask ;-), the hybrid clean into array, transform to string, and write to file takes the same total amount of time.

    What I'm doing is going through AD, getting the memberships for selected groups, and then removing those users which are member of a Disabled OU. I've got this down to 26 seconds, eclipsing my best time of 10+mins using the QAD cmdlets. Since this rarely runs even once a day, I'm OK with that performance.