PowerShell - Get open files and user in them on remote server
- Jon Boyette
- Apr 15, 2022
- 1 min read
Save as a named .ps1. add the computername, or can add it to read-host or get-content for a single machine or a list of machines, outputs all that are using files on the machine and the file paths with the usernames to csv
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 addcomputername | Export-csv c:\temp\openfiles.csv -NoTypeInformation
Comments