1

I am trying to create a web interface to allow us to monitor how many users are logged in to our 2008r2 terminal server farm. I have a script that is a good starting point and I have tweaked it for our environment, but I need to add some things and I don't know how. I need to get unique logins... here is my starting point....

$ComputerList = "RDS1","RDS2","RDS3" foreach ($ComputerName in $ComputerList){ $UserCount=0 $colEvents = Get-WinEvent -ComputerName $ComputerName - LogName "Microsoft-Windows-TerminalServices- LocalSessionManager/Operational" | Where {$_.ID -eq "21"} | Select -Property TimeCreated, Message Write-Host "`nServer Date Login Time Username" Foreach ($Event in $colEvents) { $EventTimeCreated = $Event.TimeCreated $EventMessage = $Event.Message -split "`n" | Select-Object-Index "2" $EventMessageUser = $EventMessage.Substring(6) Write-Host "$ComputerName $EventTimeCreated $EventMessageUser" $UserCount = $UserCount + 1 } Write-Host "Number of Users: $UserCount" } 

….So first things first- How to I get unique logins... Second, how do I get active logins, and third, how do I get the first script into the format of the second script? To get unique logins, Obviously, I would have to have some sort of array that the logins are stored, on the condition that there isn't already that value in the array... but I don't know how. The second would be a matter of matching an ID with one already in the list that doesn't have a logout event.... not sure how to do that either. Any ideas? I appreciate the help.

1 Answer 1

1

I'd first format the script to a readable state (indenting, line breaks)
and strip it down to only acquire data.

Without your environment taking your tweaking of properties as granted

## Q:\Test\2018\11\16\SF_940425.ps1 $ComputerList = "RDS1","RDS2","RDS3" $data = ForEach ($ComputerName in $ComputerList){ $colEvents = Get-WinEvent -ComputerName $ComputerName ` -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" | Where {$_.ID -eq "21"} | Select -Property TimeCreated, Message Foreach ($Event in $colEvents){ New-Object PSObject -Property @{ ComputerName = $ComputerName EventTimeCreated = $Event.TimeCreated EventMessage = ($Event.Message -split "`n")[2] User = $EventMessage.Substring(6) } } } $data $data | Export-Csv '.\ServerUserList.csv' -NoTypeInformation 

And doing an analysis of data lateron with the tools:

But I'd try to get a more actual PowerShell version first than the included PSv2

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.