I have an array of IDs that have corresponding directories in a share:
$ids = @('12345','25356','74678')
- C:
-- 2020
--- 12345678 SURNAME
---- 12345
----- 12345_SubDir01
----- 12345_SubDir[n]
--- 23648844 SURNAME
---- 25256
----- 25256_SubDir01
----- 25256_SubDir[n]
I want to loop through all the directories in the letter C: and find the first match (the ID not the ID with the sub directory). So I want to match on 12345 not 12345_SubDir01.
The line that I've found so far (though inefficient) works but then keeps searching until it has iterated every directory in the the root share (we have over 500,000 folders and sub-folders).
The script line I am working with:
Get-ChildItem C: -Recurse | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match "12345" }
Is there a way to get the script to stop once it has matched on the ID so it doesn't continue searching once it has found the directory?
I want to be able to use the output path in the second half of the script, but its taking about 20 minutes per ID match before it can pass it on..