Get-ChildItem exclusion from file
Hi, how load exceprion from some file, instead of: ?{($_.fullname -notmatch "foldername")} . The list can be very lage

Get-WMIObject Win32_LogicalDisk -filter "DriveType = 3" -ComputerName $computer  -ErrorAction SilentlyContinue | 

%{Get-ChildItem ('\\' + $computer + '\' + ($_.DeviceID).remove(1) + '$\*') -File *.doc,*.docx -Recurse  -Force -ErrorAction SilentlyContinue | 

?{($_.fullname -notmatch "Windows") -and ($_.fullname -notmatch "Program Files") -and ($_.fullname -notmatch "Program Files (x86)")} |

Add-Content $env:TEMP\$computer.txt


Thank!
September 5th, 2015 3:38am

Hi,

you could try using regex comand | for or using the -notmatch operator.

You have to escape the parentheses with \

Like this:

?{($_.fullname -notmatch "Windows|Program Files|Program Files \(x86\)") 

If you have many exclusions you could also add them like this - to have an better overview:

$exclusions=@(

"Windows"

"Program Files"

"Program Files(x86)"

) $exclusions = ($exclusions -join "|").Replace('(','\(').Replace(')','\)')

Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 10:18am

Thank! It works :)  an you explain why use "\" in path? Sorry I don't understand :)

Program Files \(x86\


September 5th, 2015 3:24pm

Thank! It works :)  an you explain why use "\" in path? Sorry I don't understand :)

Program Files \(x86\


Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 3:24pm

Nice to hear.

The parentheses would otherwise work as operating command.

By escaping the parentheses with \ the regex operator knows that this is part of the string which to search. You have to place the escaping character (in this example \ ) before any parenthesis.


 
September 5th, 2015 4:18pm

You can also automate the placement of the \ characters:
[regex]::Escape('Program Files (x86)')


Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 7:10pm

Thank! It works :)  an you explain why use "\" in path? Sorry I don't understand :)

Program Files \(x86\


September 5th, 2015 7:22pm

You can also automate the placement of the \ characters:
[regex]::Escape('Program Files (x86)')


Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 11:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics