open Files

rated by 0 users
This post has 4 Replies | 2 Followers

Top 50 Contributor
Posts 58
Top Contributor
Bernard Posted: 06-02-2009 8:59 AM

Hi ya all :)

Is there a way to query on a server the open Files and open sessions with powershell ?

Top 50 Contributor
Posts 58
Top Contributor

A little more information why i ask :

We are implementing softwaredeployment via DFS.
In orther words : it does not mather from what server the MSI comes from.

I want to monitor the open Files on all of the DFS servers so i know if the DFS mechanism works.

Top 50 Contributor
Posts 58
Top Contributor

I found this script to sum up the sessions between the remote server and user (and IP). Is there a way to show the open file ?


$server = "server"
$adsi = [adsi]"WinNT://$server/LanmanServer"
$user = $adsi.psbase.invoke("sessions") | foreach {$_.gettype().invokeMember("user","GetProperty",$null,$_,$null)}
$computer = $adsi.psbase.invoke("sessions") | foreach {$_.gettype().invokeMember("computer","GetProperty",$null,$_,$null)}

for($i=0;$i -lt $user.length; $i++) { "{0}@{1}" -f $user[$i],$computer[$i] }

Top 25 Contributor
Posts 517
Microsoft MVP
Top Contributor

You can try this:

$server = "server"
$adsi = [adsi]"WinNT://$server/LanmanServer"
$users = $adsi.psbase.invoke("resources") | foreach {$_.gettype().invokeMember("user","GetProperty",$null,$_,$null)}
$paths = $adsi.psbase.invoke("resources") | foreach {$_.gettype().invokeMember("path","GetProperty",$null,$_,$null)}

for($i = 0;$i -lt $users.length; $i++) { "{0}: {1}" -f $users[$i],$paths[$i] }

Or you can use WMI class Win32_ServerConnection:

Get-WmiObject win32_serverconnection -computerName $server |
Format-Table connectionid,username,computername,sharename,activetime,number* -auto

There is also legacy command net file that you can use like this:

$server = "server"
$command = 'cmd /k net file > c:\openfiles.txt'
([wmiclass]"\\$server\root\cimv2:Win32_Process").create($command)
Invoke-Item \\$server\c$\openfiles.txt
# Remove-Item \\$server\c$\openfiles.txt
Top 50 Contributor
Posts 58
Top Contributor

Hi Aleksandar,

Thanks for these directrions ..i will them.

(its a little late reaction .. i had some other projects to work on ;) )

Page 1 of 1 (5 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.