Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Count user sessions

$
0
0

Hello,

we use a script each day to check the health status of our Citrix enviroment. The Citrix operators recieve a mail wich looks like this... I removed some company data...

The first column contains the server name and to the right of that are columns we use for important data.

I added the column "Aantal Gebruikers" wich means number of users in English. What i want there is a number of currently connected users so that when a server does not accept sessions i can see that right away.

In the script i created i tried a function but it does not work.

function Get-ADProperties($Item){
    $root = [ADSI]''
    $searcher = new-object System.DirectoryServices.DirectorySearcher($root)
    $searcher.filter = "(&(objectClass=computer)(Name=$Item))"
    $Result = $searcher.findone()
    return $Result.properties
}

function Get-Uptime($Server)  {
    $wmi = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server
    $Uptime = $wmi.ConvertToDateTime($wmi.LastBootUptime).ToString('dd-MM-yyyy')
    return $Uptime
}                

Function Get-ComputerSessions {

[cmdletbinding(
    DefaultParameterSetName = 'session',
    ConfirmImpact = 'low'
)]
    Param(
        [Parameter(
            Mandatory = $True,
            Position = 0,
            ValueFromPipeline = $True)]
            [string[]]$Server
            )
Begin {
    $reportgebruikers = @()
    }
Process {
    ForEach($c in $Server) {
        # Parse 'query session' and store in $sessions:
        $sessions = query session /server:$c
            1..($sessions.count -1) | % {
                $temp = "" | Select Computer,SessionName, Username, Id, State, Type, Device
                $temp.Computer = $c
                $temp.SessionName = $sessions[$_].Substring(1,18).Trim()
                $temp.Username = $sessions[$_].Substring(19,20).Trim()
                $temp.Id = $sessions[$_].Substring(39,9).Trim()
                $temp.State = $sessions[$_].Substring(48,8).Trim()
                $temp.Type = $sessions[$_].Substring(56,12).Trim()
                $temp.Device = $sessions[$_].Substring(68).Trim()
                $reportgebruikers += $temp
            }
        }
    }
End {
    $reportgebruikers
    }
}

Can someone tell me what i did wrong?


Viewing all articles
Browse latest Browse all 6937