Openfiles query to see open files

50.8k views Asked by At

How can I call the Openfiles.exe (which is on the server 2008 file server) remotely from a computer to see which files are open by the users? I also need to have it login as the domain admin user in the parameters.

7

There are 7 answers

13
AudioBubble On BEST ANSWER

Openfiles can do a server direct. You don't have to run it remotely.

From Help openfiles /query /?

OPENFILES /Query /S system /U username /P password /NH
1
Zam On

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.

0
mjolinor On

You can use a remote delegated powershell session for this.

Use Delegated Administration and Proxy Functions

You can delegate the admin credentials in RunAs setting of the session configuration, and constrain the session to only being able to run the openfiles.exe. Then you can assign permission to use to session to selected groups or users. This enables you to let people run cmdlets or programs that require domain admin authority, without giving them the domain admin credentials.

1
Unfundednut On

A way to do it in PowerShell and to allow for searching would be with this small function.

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
}

It allows you to call Get-OpenFiles Server Filename and it will show you the results. The caveat is that you have a folder called C:\temp.

So if I do Get-OpenFiles TestServer Hardware I get the below.

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
0
expirat001 On

Here is a solution without creating temporary files.

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
0
DragonKing On

You can now do this with the PowerShell command Get-SmbOpenFile.

0
Kirt Carson On

No need to create a CSV file and have to remove it later, or be concerned about its' size.

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

If you're using powershell 1.0 then add |select -skip 8| before the convertfrom-csv portion.