none
PowerShell to Check who has Open Files RRS feed

  • Question

  • Does anyone know of any PowerShell commands that can be used to check to see who has open files on a remote file server.  I am aware of the openfile command and the psfile command that comes with sysinternals.  The problems is that our developers have created various interfaces for our Support Center to use that field tech support calls.  They get a lot of calls about checking on who has open files that then get forwarded to us.  If we can find the right PowerShell commands, the developers can add the functionality to the interface that Support Center uses so the calls don't always come to us.  the openfile and psfile commands may not work for our needs.  Any help you can provide would be great.  Let me know if you have any questions.  Thanks!!!
    Friday, March 18, 2016 1:46 PM

Answers

  • If openfiles works, then you can use it directly from PowerShell. Use CSV output format and then pipe to ConvertFrom-Csv. For example:


    PS C:\> openfiles /query /s servername /fo csv | ConvertFrom-Csv
    

    ConvertFrom-Csv converts the CSV output from the openfiles command into objects. From there you can sort, filter, etc.


    -- Bill Stewart [Bill_Stewart]

    Monday, March 21, 2016 8:15 PM
    Moderator

All replies

  • Hi,

    If you have powershell 4.0 you can use the cmdlet Get-SmbOpenFile

    Thank you.

    JP


    Friday, March 18, 2016 1:56 PM
  • Hi,

    If you have powershell 4.0 you can use the cmdlet Get-OpenSmbFile

    Thank you.

    JP

    YEs but spelled Get-SmbOpenFile


    \_(ツ)_/

    Friday, March 18, 2016 2:02 PM
  • Thanks.  I'm aware of Get-OpenSmbFile but I'm confused as to the best way to use it in this scenario.  We would want to run it against the remote file server.  The file server is not a Windows server by the way.  As a test I could do an enter-pssession on a Windows Server and then do a Get-OpenSmbFile but even then I was seeing only File IDs and Session IDs but not exactly the File Names.  If I did an enter-pssession on the actual file server that we use I got an error message because that isn't even a Windows server.  Is there a way to run this particular command (or a different powershell command) against the remote server and be able to say "person x has file z open." ?  What would the syntax for that be?  Thanks again for your help.
    Friday, March 18, 2016 6:13 PM
  • The file server is not a Windows server by the way.
    Well...that detail is a bit important. Of course, this is a Microsoft forum for Windows OS scripting questions. The remote system would need to have a way to query open files remotely, but that is not a question for this forum.

    -- Bill Stewart [Bill_Stewart]

    Friday, March 18, 2016 6:23 PM
    Moderator
  • Get-SmbOpenFiles will only work with Windows systems.  It may work with NFS extensions installed but I have not tried that.

    You have to turn your thinking around:

    $server='myremoteserver'
    Get-SmbOpenFile -ScopeName $server

    https://technet.microsoft.com/library/20aa3a6f-38d3-4692-98e5-4f510b9be782%28v=wps.630%29.aspx?f=255&MSPPError=-2147217396

    To get a list of open files from a share we would use: https://gallery.technet.microsoft.com/Enumerate-OPen-Files-on-feb939f7

    Remember that all servers are not SMB enabled.


    \_(ツ)_/

    Friday, March 18, 2016 6:38 PM
  • Non windows systems can be SMB but must have the SMB management MOFs installed. The Smb commands use Cim  to query the remote system.  Only Windows 8.1 and later come equipped with support for the SMB commands.


    \_(ツ)_/

    Friday, March 18, 2016 6:41 PM
  • Okay, thanks everyone.  I tried the Get-SmbOpenFile -ScopeName command and got an error message with No MSFT_SMBOpenFile objects found with property 'ScopeName' equal to etc...  So that kind of makes sense.  I didn't even think to mention that it wasn't a Windows machine at first (sorry Bill) because the openfile command and the psfile commands worked just fine.  I'll go back to the developer I am working with and see if those can be used and if not see if we can work with installing something on the file server side so we can actually run the necessary powershell commands.  Thanks again for all of your assistance.
    Monday, March 21, 2016 7:30 PM
  • If openfiles works, then you can use it directly from PowerShell. Use CSV output format and then pipe to ConvertFrom-Csv. For example:


    PS C:\> openfiles /query /s servername /fo csv | ConvertFrom-Csv
    

    ConvertFrom-Csv converts the CSV output from the openfiles command into objects. From there you can sort, filter, etc.


    -- Bill Stewart [Bill_Stewart]

    Monday, March 21, 2016 8:15 PM
    Moderator