powershellget-childitem

Get-ChildItem exclude multiple full path


I'd like to use Powershell script that search files greater than 30GB. But I'd like to exclude from search, multiple files by full path. Files patchs are in external txt file. I try use -notike and -Exclude. But without success. Ewery time I get list of all files. Any sugestions how to do this correctly.

$exclude = @(Get-Content c:\exclude.txt)
Get-ChildItem -Path c:\users -Include *.* -Recurse | where-object{$_.fullname -notlike $exclude} | where-object {$_.length -gt 35000000000}

c:\exclude.txt

C:\users\tom\36gb.txt,C:\users\john\38gb.txt

I'd like get list of files that not include files from c:\exclude.txt


Solution

  • You can use the -notin comparison operator but each path in the exclude.txt file should be in a new line:

    C:\users\tom\36gb.txt
    C:\users\john\38gb.txt
    

    Then you can do:

    $exclude = Get-Content c:\exclude.txt
    Get-ChildItem -Path c:\users -Recurse -File |
        Where-Object { $_.Length -gt 30Gb -and $_.FullName -notin $exclude }