sanhutrees 发表于 2018-9-2 07:17:15

Powershell 遍历磁盘下的文件夹

CD "D:\Symantec\Scan Engine\CmdLineScanner\"  
Write-Host "开始扫描以a打头的文件!"
  

  
Get-ChildItem -path z:\| where {$_.Name -match "^a"} | select fullname| Out-File files.txt #获取以a开头的文件及文件夹,输出到a.txt文件中
  

  
$file = Get-Content "files.txt" #将files.txt 内容赋给$file
  

  
$file -replace "(?m)\s","" > files.txt #删除a.txt文件中的空格
  

  
$file = Get-Content "files.txt"
  

  
$file = $file | Out-File files.txt #删除文件中的前三行描述信息,输出的内容覆盖a.txt文件内容
  

  
$file = Get-Content "files.txt"
  
foreach ($check in $file)
  
{
  
    $check = """$check""" #给轮循的内容加上双引号
  
    cmd/cssecls.exe -server 127.0.0.1:1344 -mode scan -recurse -api 1 -exclude exclude.lst -log a%DATE%.log $check >> a%DATE%-result.log
  
    Write-Host $check "扫描完毕"
  
}
  
write-host "以a打头的文件扫描完毕!"


页: [1]
查看完整版本: Powershell 遍历磁盘下的文件夹