I need to generate a configuration file for our Pro/Engineer CAD system. I need a recursive list of the folders from a particular drive on our server. However I need to EXCL
The exclusion pattern should be case-insensitive, so you shouldn't have to specify every case for the exclusion.
That said, the -Exclude
parameter accepts an array of strings, so as long as you define $archive
as such, you should be set.
$archive = ("*archive*","*Archive*","*ARCHIVE*");
You also should drop the trailing asterisk from $folder
- since you're specifying -recurse
, you should only need to give the top-level folder.
$folder = "T:\Drawings\Design\"
Fully revised script. This also changes how you detect whether you've found a directory, and skips the Foreach-Object
because you can just pull the property directly & dump it all to the file.
$folder = "T:\Drawings\Design\";
$raw_txt = "T:\Design Projects\Design_Admin\PowerShell\raw.txt";
$search_pro = "T:\Design Projects\Design_Admin\PowerShell\search.pro";
$archive = ("*archive*","*Archive*","*ARCHIVE*");
Get-ChildItem -Path $folder -Exclude $archive -Recurse | where {$_.PSIsContainer} | select-Object -expandproperty FullName |out-file $search_pro