2

如何从计算机远程调用 Openfiles.exe(位于服务器 2008 文件服务器上)以查看用户打开了哪些文件?我还需要让它作为参数中的域管理员用户登录。

4

7 回答 7

5

Openfiles 可以直接做服务器。您不必远程运行它。

从帮助openfiles /query /?

OPENFILES /Query /S system /U username /P password /NH
于 2015-05-10T04:13:53.950 回答
3

在 PowerShell 中执行此操作并允许搜索的一种方法是使用这个小函数。

function Get-OpenFiles {
    cls
    openfiles /query /s $args[0] /fo csv /V | Out-File -Force C:\temp\openfiles.csv
    $search = $args[1]
    Import-CSV C:\temp\openfiles.csv | Select "Accessed By", "Open Mode", "Open File (Path\executable)" | Where-Object {$_."Open File (Path\executable)" -match $search} | format-table -auto
    Remove-Item C:\temp\openfiles.csv
}

它允许你打电话Get-OpenFiles Server Filename,它会告诉你结果。需要注意的是,您有一个名为 C:\temp 的文件夹。

因此,如果我这样做,Get-OpenFiles TestServer Hardware我会得到以下信息。

Accessed By Open Mode    Open File (Path\executable)
----------- ---------    ---------------------------
NFDJWILL    Read         N:\Network Services\Documentation\Hardware.xlsx
NFDJWILL    Write + Read N:\Network Services\Documentation\Hardware.xlsx
NFDJWILL    Read         N:\Network Services\Documentation\Hardware.xlsx
于 2015-11-16T18:24:55.520 回答
2

这是一个不创建临时文件的解决方案。

function Get-OpenFile
{
    Param
    (
        [string]$ComputerName
    )

    $openfiles = openfiles.exe /query /s $computerName /fo csv /V

    $openfiles | ForEach-Object {

        $line = $_

        if ($line -match '","')
        {
            $line
        }

    } | ConvertFrom-Csv
}

Get-OpenFile -ComputerName server1
于 2016-07-09T20:17:23.683 回答
2

您现在可以使用 PowerShell 命令 Get-SmbOpenFile 执行此操作。

于 2017-08-29T20:23:04.810 回答
0

how to run application remotely by using Power Shell https://technet.microsoft.com/en-us/library/dd819505.aspx

your PS or BAT script will be:

openfiles.exe > c:\temp\openfiles.txt

of course better use different output folder and file name.

Alternative way: https://technet.microsoft.com/en-ca/sysinternals/bb897553.aspx -- PsExec -- PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

于 2015-05-09T22:28:25.417 回答
0

您可以为此使用远程委托的 powershell 会话。

使用委托管理和代理功能

您可以在会话配置的 RunAs 设置中委派管理员凭据,并将会话限制为只能运行 openfiles.exe。然后,您可以将使用会话的权限分配给选定的组或用户。这使您可以让人们运行需要域管理员权限的 cmdlet 或程序,而无需向他们提供域管理员凭据。

于 2015-05-09T23:07:33.990 回答
0

无需创建 CSV 文件并在以后删除它,或者担心它的大小。

openfiles /s MyFileSrv /query /fo CSV /v /u admin1 /p myPass | convertfrom-csv  |?{$_.'Open File (Path\executable)' -match "MyFolder"} |select 'Accessed By', 'Open Mode', 'Open File (Path\executable) 

Accessed By Open Mode    Open File (Path\executable)
----------- ---------    ---------------------------
robinsonl   Write + Read D:\Dept\MyFolder
smithd      Read         D:\Dept\MyFolder\info

如果您使用的是 powershell 1.0,则添加 |select -skip 8| 在 convertfrom-csv 部分之前。

于 2018-06-29T16:23:35.227 回答