新しい Powershell 4.0/Win2012 コマンドレット以外は何も見つからなかったので、独自のスクリプトを作成しました。共有する価値があると思いました。
# Use "net files" to get the ID's of all files and directories on this computer
# that are being accessed from a network share.
$openFiles = net files |
where { $_ -match "^(?<id>\d+)" } |
foreach {
# Use "net files <id>" to list all information about this share access as a key/value list, and
# create a new PSObject with all this information in its properties.
$result = new-object PSObject
net files $matches["id"] |
where { $_ -match "^(?<key>.*[^\s])\s{2,}(?<value>.+)$" } |
foreach {
Add-Member -InputObject $result -MemberType NoteProperty -Name $matches["key"] -Value $matches["value"]
}
return $result
}
# Now that we know everything that's being accessed remotely, close all that
# apply to our application folder.
$openFiles |
where { $_.Path -like "C:\MySharedFolder\MyApp*" } |
foreach { net files ($_."File Id") /close }