Powershell命令监控被打开的共享文件,如果超过一分钟还没被释放,则自动强行关闭文件占用。

可以用nssm做成Windows Services,自动运行。

while ($true)
{
    function closeopenfile {
        foreach($file in get-smbopenfile | ? {$_.Path -like "*.tar" -and -not ($_.ClientUserName -like "JABIL\SV*")})
        {
            $m = Get-Item $file.Path | Where{$_.LastWriteTime -lt (Get-Date).AddMinutes(-1)} | measure
            $m.Count
            if($m.Count -eq 1) {close-smbopenfile -SessionId $file.SessionId -Confirm:$false}
        }
    }
    closeopenfile
    Start-Sleep -Seconds 60
}

 

相关文章:

  • 2021-11-20
  • 2022-02-08
  • 2021-08-11
  • 2021-11-23
  • 2021-05-10
  • 2021-07-29
  • 2021-05-20
  • 2021-07-24
猜你喜欢
  • 2021-10-19
  • 2021-12-19
  • 2021-06-17
  • 2022-12-23
  • 2021-10-11
  • 2021-06-28
  • 2021-12-16
相关资源
相似解决方案