Powershell从进程中排除目录

时间:2015-02-02 20:19:37

标签: powershell command-line

我是Power Shell脚本的新手。我已经有了这个代码。这是有效的,但我想从$ exclude变量中排除路径,因此在运行process.exe时它不会包含在进程中。是否可以排除路径?提前谢谢!

$exclude = Get-ChildItem -Path 'C:\SCRIPTS\tester\TESTALL\excludethisfolder\' -Recurse  | Where-Object{!($_.PSIsContainer)}
$Allfiles = Get-ChildItem -Path "C:\SCRIPTS\tester\processthisfolder\" -Recurse | where{!$_.PSIsContainer -and $_.CreationTime -gt $oldday } | Select-Object FullName

foreach ($file in $Allfiles) #check for each file in variable $Allfiles)
        {
           $file1 = $file.Fullname
           $foldername = Get-ChildItem -Path $file.FullName
           $input = $foldername.DirectoryName
           $Mothername = Get-Item -Path $input
           $output = $Mothername.Parent.Fullname
           $output = "$output\sc"
           Write-Host "The Filename: $file1"
           Write-Host "The FolderName: $input"
           Write-Host "$output"
           Write-Host "$Excludefolder"
           $argument = "$input $output $input"
           Start-Process -FilePath "C:\SCRIPTS\process.exe" -ArgumentList $argument #execute the process
        }
        Clear-variable -Name Allfiles

1 个答案:

答案 0 :(得分:0)

修改where子句以过滤掉以exclude dir开头的路径:

$Allfiles = Get-ChildItem C:\SCRIPTS\tester\processthisfolder -Recurse |
               Where {!$_.PSIsContainer -and ($_.CreationTime -gt $oldday) -and !$_.FullName.StartsWith('C:\SCRIPTS\tester\TESTALL\excludethisfolder\') } | 
               Select FullName