Author Posts

June 23, 2015 at 10:04 am

im trying to do a "get-childitem" search of directories that are all named with numbers.
a 5 digit minimum consisting of digits from 0 to 9. directory example names like the following "13476" or "334787"
tried the below.. among many other attempts, and cant seem to get the results I'd like.

get-childitem c:\users | where-object {$_.name -like '*0-9*' }

how can I accomplish this?

June 23, 2015 at 10:16 am

ok.. I got this to return correctly.. is this the best way to accomplish it?
basically.. I want it to return directory names that contain any integer of any length.

get-childitem c:\users | where-object {$_.name -match '[0-9]' }

June 23, 2015 at 11:28 am

Try something like this

Get-ChildItem -Path c:\ | Where-Object {$_.BaseName -match '(^\d[0-9])'}

I did test and it only gave me the folders that start with numbers.

June 24, 2015 at 4:41 am

awesome.. thanks for the suggestion.

June 24, 2015 at 11:26 pm

use \d+ or \d{min.max} syntax if you want to get 1+ or min to max numbers length. btw, \d its the same as [0-9]

"^\d+$" – give names that contains numbers only
"^\d{3,6}$" – give names that contains numbers only but only from 3 to 6 characters long
"^\d{5,}$" gives what you want – all digits, five or more

June 25, 2015 at 8:14 am

You can actually filter with Get-ChildItem:

Get-ChildItem -Path "C:\test\[0-9]*"

It's referenced in this Powershell Tip:

https://technet.microsoft.com/en-us/library/ff730956.aspx

June 30, 2015 at 5:55 am

thanks for the extra tips rob and max. its appreciated.
now that ive got this aspect of the script working.. im running into the 256 character limit on directory length. always something.
thanks again guys for all the help