0

変更をファイル共有にプッシュすると、ユーザーがアプリケーションを開いたままにして、ファイルを共有から開いたままにすることがあります。ファイルはロックされており、置き換えることはできません。そのようなファイルに対応する共有セッションを見つけて、ファイルを上書きする前に、PowerShellスクリプトでそれら(これは読み取り専用のもの、主に.DLLファイル)を強制終了したいと思います。

これは、共有フォルダーMMCで開いているファイルを見つけて、そこで対応するセッションを閉じるのと同じですが、複数のサーバーに対してプログラムでリモートで実行する必要があります。

4

2 に答える 2

1

新しい 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 }
于 2014-12-09T17:19:41.383 に答える
0

net file /closeの何が問題になっていますか?

于 2012-05-04T06:28:59.407 に答える