-match
is like asking for *Program Files*
. You should be using the -Filter
parameter of Get-ChildItem
for something like this. It's a lot faster and doesn't require regex escape etc.
PowerShell 3:
$folderName = "Program Files"
(gci -path C:\ -filter $foldername -Recurse).FullName
PowerShell 2:
$folderName = "Program Files"
gci -path C:\ -filter $foldername -Recurse | Select-Object -Expand FullName
Also, you should not use -Recurse
if you don't need it(like in this example).