2017/2/9

查詢網路磁碟機上檔案被誰開啟以及使用者名稱,使用openfile +powershell


參考來源:
http://stackoverflow.com/questions/9728692/format-table-output-from-openfiles-exe

將下面指令貼到powershell(最好在AD上,或者有機器能執行get-ADUser指令,比較好查是誰)
紅色部分代表修改需要的目標或者關鍵字

function Get-filenasOpenFiles { openfiles /query /fo table /s filenas /v |
    Select-Object -Skip 2 |
    Foreach-Object {
        if ($_ -match '([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.*)') {
            New-Object PsObject -prop @{
                HOSTNAME=$matches[1];
                Id=$matches[2];
                AccessedBy=$matches[3];
                Type=$matches[4];
                LOCKS=$matches[5];
                OpenMode=$matches[6];
                OpenFile=$matches[7]
            }
        }
    } }

$queryfileName='月生產'
get-filenasopenfiles |where-object {$_.openfile -match $queryfileName} |select accessedby,openmode,openfile  |Format-Table -AutoSize
$openfileUser=get-filenasopenfiles |where-object {$_.openfile -match $queryfileName} |select accessedby
foreach ($openusers in $openfileUser ){get-aduser -filter * -Properties Name|where-object {$_.samaccountname -eq $openusers.AccessedBy} |select name}


2017/04/17補充:
如果要改抓只有編輯,則該行增加一段過濾
get-filenasopenfiles |where-object {$_.openfile -match $queryfileName }|where-object  {$_.openmode -match 'Write'} |select accessedby,openmode,openfile  |Format-Table -AutoSize

沒有留言:

windows 無法拖動文件

原因:未知 症狀:windows點任何文件,都無法拖動到其他地方  解決方式: 來源: https://answers.microsoft.com/en-us/windows/forum/all/drag-and-drop-stopped-working/b73e4938-ca2...