I need to monitor how many share sessions are on my fileservers. Is there a way to do this with PRTG?
Can you monitor server share sessions with PRTG?
Votes:
0
13 Replies
Votes:
1
This article applies to PRTG Network Monitor 13 or later
Fileshare Active Sessions Sensor
Using the code below in an EXE/Script Advanced sensor will allow you to query a server and find out
- how many unique users have share sessions open,
- how many unique computers have unique sessions open,
- and the total number of share sessions for the computer.
Note: For this sensor to work, you need to define the computer's name in the parameters field. You can also enter in multiple computer names and gather the stats for all of the defined servers in total. You can also use the %host variable here to use the parent device in the sensor.
$computer = $args $namespace = "root\CIMV2" $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace $users=$usersessions | select UserName -unique $users=$users.count $Sessions=$usersessions | select ConnectionID -unique $Sessions=$Sessions.count $Computers=$usersessions | select ComputerName -unique $Computers=$Computers.count Write-Host "<prtg>" "<result>" "<channel>Total Users connected to Shares</channel>" "<value>"+ $users +"</value>" "</result>" "<result>" "<channel>Total Computers connected to Shares</channel>" "<value>"+ $Computers +"</value>" "</result>" "<result>" "<channel>Total Share Sessions</channel>" "<value>"+ $Sessions +"</value>" "</result>" "<text>" + $Sessions + " Total Sessions</text>" Write-Host "</prtg>"
Created on Aug 27, 2013 1:55:00 PM by
Greg Campion [Paessler Support]
Last change on Jun 25, 2014 4:42:05 PM by
Greg Campion [Paessler Support]
Votes:
0
I found a couple additional things needed to be done for this to work:
1. You'll need to allow the execution of Powershell scripts on the probe system via "Set-ExecutionPolicy Unrestricted" or the script won't run. On a x64 server I had to do this specifically in the x86 PowerShell instance.
2. The server name needs to be entered in the parameters field (as noted) with the name surrounded in quotes.
3. Change "Security Context" to "Use Windows Credentials of parent device."
James
Votes:
0
Thanks for posting that information James!
Votes:
0
Is there a need to modify the above script for monitoring a remote server?
I was successful applying the demo script, prtg provides, to the target server, following the hints from james.
here is what I did, when I tried to add a second script with the content from above:
I set the security information in powershell as requested. I copied the demo batchfile prtg provides and replaced the content with the script from above. I added the advanced exe sensor to the target machine I want the information from, in our case a windows 2008 file server. I entered the FQDN of the server into parameters, like 'example.local' I chose, as written above parent security context.
I received the "Error reading response: missing /prtg" Error.
Is there anything else I have to take care of?
I assume that the given script from above is still valid, as I am not firm with scripting...
thank you in advance for your response
regards Oliver
Votes:
0
Can you run the script directly in PowerShell? Please try to replace the first line with
param($computer)
...and see if PRTG executes it properly? At least that was needed to make it run in PowerShell without errors. Seems like the $args variable is no longer used, hence it's not working anymore.
You should be able to call it like this:
.\Get-Shares.ps1 your-server-name
Created on Sep 17, 2014 12:35:02 PM by
Stephan Linke [Paessler Support]
Last change on Sep 17, 2014 12:36:25 PM by
Stephan Linke [Paessler Support]
Votes:
0
Has anyone seen this error when trying to use the above script? I can run the powershell script with no issues from the server running the PRTG local probe
XML: Structural error in xml file, 1 open items. -- JSON: The returned json does not match the expected structure (Invalid JSON.). (code: PE231)
Votes:
0
Can you post here was the result looks like when you run the script with Powershell?
Votes:
0
I am impressed with this script; however I have all "0" in all fields even thought I am connected to shares and have files opened - any thoughts?
Votes:
0
Dear AdamG
Please enable the sensor option "Write Exe result to disk". The logs appear in "C:\ProgramData\Paessler\PRTG Network Monitor". Do you see a powershell / WMI error message in the script result?
Votes:
0
Thank You Arne, I was able to fix that with submitting ticket and get help, but wonder if we can use similar script which shows user names (AD) connected to file server, now I see only digits but would be wonderful if I see what users are connected - names. Person who is helping me send me:
$computer = "localhost"
$namespace = "root\CIMV2" $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace
$users=$usersessions | select UserName -Unique $users_list=($users | select -expand UserName) -join ", " $users_count=$users.count
$Sessions=$usersessions | select ConnectionID -unique $Sessions=$Sessions.count
$Computers=$usersessions | select ComputerName -unique $Computers=$Computers.count
Write-Host "<prtg>" "<result>" "<channel>Total Users connected to Shares</channel>"
"<value>"+ $users_count +"</value>" "</result>"
"<result>" "<channel>Total Computers connected to Shares</channel>" "<value>"+ $Computers +"</value>" "</result>"
"<result>" "<channel>Total Share Sessions</channel>" "<value>"+ $Sessions +"</value>" "</result>"
"<text>" + $Sessions + " Total Sessions - Usernames: " + $users_list + "</text>" Write-Host "</prtg>"
But I have none data - all sensors shows 0 - any thoughts?
Votes:
0
Dear AdamG
What is the exact issue? Getting no names, or getting zero values? Only the sensor status message can have text (channel data only stores numbers, not strings.) If the message string is empty, or if you get no data in the first place, please again enable the Write Exe result to disk option to see there is an error during the script execution.
Created on May 19, 2017 3:16:06 PM by
Arne Seifert [Paessler Support]
Last change on May 19, 2017 3:18:53 PM by
Arne Seifert [Paessler Support]
Votes:
0
I have found very usable script but after spending some time I don't know how to implement into this custom sensor:
$computer = $args $namespace = "root\CIMV2" $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace
if($userSessions -ne $null)
{ Write-Host "The following users are connected to your PC: "
foreach ($userSession in $userSessions) { $userDetails = [string]::Format("User {0} from machine {1} on share: {2}", $userSession.UserName, $userSession.ComputerName, $userSession.ShareName) Write-Host $userDetails }
Write-Host }
Output is:
The following users are connected to your PC: User test from machine 1.1.1.1 on share: test User test2 from machine 1.1.1.2 on share: test2
But after changing script to:
$computer = $args $namespace = "root\CIMV2" $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace
$users=$usersessions | select UserName -unique $users_list=($users | select -expand UserName) -join ", " $users=$users.count
- $userDetails = [string]::Format("User {0} from machine {1} on share: {2}", $userSession.UserName, $userSession.ComputerName, $userSession.ShareName)
$Sessions=$usersessions | select ConnectionID -unique $Sessions=$Sessions.count
$Computers=$usersessions | select ComputerName -unique $Computers=$Computers.count
if($userSessions -ne $null)
{ Write-Host "<prtg>"
"<result>" "<channel>Connection Details</channel>" foreach ($userSession in $userSessions) { $userDetails = [string]::Format("User {0} from machine {1} on share: {2}", $userSession.UserName, $userSession.ComputerName, $userSession.ShareName)
- Write-Host $userDetails "<value>"+ $userDetails +"</value>" }
"</result>"
"<result>" "<channel>Total Users connected to Shares</channel>" "<value>"+ $users +"</value>" "</result>"
"<result>" "<channel>Total Share Sessions</channel>" "<value>"+ $Sessions +"</value>" "</result>"
"<result>" "<channel>Total Computers connected to Shares</channel>" "<value>"+ $Computers +"</value>" "</result>"
"<text> Connection Details: "+ $userDetails +"</text>"
Write-Host "</prtg>" }
I have in text field only last line listed in all shares - I am missing something simple.....
Votes:
0
Dear AdamG
To debug this script, please manually output the important variables like $userSessions and $users. Check if the content is correct. If that is the case, please check how you process it for the XML return.
Add comment