Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows Server 2012 R2 / How to See Number of Active User Sessions on IIS site?

November 2, 2018 PowerShellWindows Server 2012 R2Windows Server 2016

How to See Number of Active User Sessions on IIS site?

How to quickly estimate the current number of user connections (sessions) to the IIS sites on webserver running on Windows Server? Such information will allow to determine and predict the load on the server, choose the best time for the maintenance and updates of the website, predict the IIS server’s load when the number of users increases.

The easiest way to determine the number of active user sessions on the IIS Web site is to use the performance counters in Windows Performance Monitor.

Open the Performance Monitor console by running the perfmon command and go the Performance monitor section (Monitoring Tools — > Performance Monitor).

Then you need to add the necessary counters to the monitor window (by default, the total CPU usage counter is displayed, but you can remove it). To add a new counter, click the green button on the toolbar (you can see it on the screenshot) or press Ctrl+N on the keyboard.

windows performance monitor

In the list of available counters, find and expand the Web Service group. In this category, we are interested in three counters:

  • Current Anonymous Users – the number of anonymous IIS users;
  • Current Non-Anonymous Users – the number of authorized IIS users;
  • Current Connections – total number of active connections on the IIS server.

Select the desired counter and in the Instances of selected objects choose one or more IIS websites for which you want to display connection information. The information about users of all websites on the server is stored in the _Total instance. Now you only have to click the Add >> button to move the counter to the list of the counters to be added in the right pane.

iis performance counters

Add all the necessary counters in the same way and click OK.

iis current user connections graph

Now the information about the number of user sessions in the Performance Manager console is being displayed in the real time (by default, the counter values are displayed as linear graphs). If you select any of the counters in the bottom pane, you can view its last, average, minimum or maximum value for a given period of time.

You can add custom performance counters to this console and save them in a separate view, which can be used later to quickly access the web server load data.

You can access the IIS performance counters from PowerShell. To do this, you can use the Get-Counter cmdlet. The list of all available Web Service performance counters can be displayed as follows:

(Get-Counter -ListSet 'Web Service').counter

Get-Counter Web-Service

To get information about the current number of active connections on the IIS server (the counter \Web Service(*)\Current Connections), use this command:

Get-Counter -Counter “\Web Service(*)\Current Connections”

As you can see, this command returned both the total number of connections to the IIS server and the statistics for each of the sites.

Tip.

  • The values of several counters can be displayed if you specify them separated by the commas;
  • With the –Continuous option, the information about the value of the counter is constantly displayed in the console until you’ll interrupt it using CTRL+C.

You can get the number of active sessions for a specific IIS site. For example, to get the current number of connections on a site named Site1, run the following command:

Get-Counter "web service(Site1)\current connections" -ComputerName web-srv01

You can specify the name of the server on which the counter value is checked. When you are checking the number of connections on the site locally, specifying localhost is not allowed:

powershell get iis connections
In order not to specify the server name each time, you can use the environment variable COMPUTERNAME:

Get-Counter "web service(Site1)\current connections" -ComputerName $env:COMPUTERNAME

To get the numeric value of the counter “current connections” of the entire IIS web server (total users on IIS), you can use this command:

((Get-Counter -Counter 'web service(_total)\current connections' -computer $env:COMPUTERNAME) |     Select-Object -Expand countersamples).Cookedvalue

Let’s try using a simple script to create several additional sessions with our site and check the counter value. You can increase the number of connections to the IIS website using the Invoke-WebRequest cmdlet, or you can simply open several windows in the browser:

$counter = 20
for($i=1;$i -le $counter;$i++){
$SiteAdress = "http://localhost:9666/"
Start-Process $SiteAdress
}

Check the value of the current connections counter and make sure that it increases.

If several IIS sites are running on the server, and you need to get the number of connections to each of them in a form of table, you can use this script (to receive data from IIS into PowerShell, you need to load the WebAdministration module):

import-module webadministration
function get-CurrentConnection($Site) {
Get-Counter "web service($Site)\current connections,web service($Site)\ Bytes Received/sec,web service($Site)\Bytes Sent/sec" -ComputerName $env:COMPUTERNAME
}
$IISsites = dir IIS:\Sites | Select Name
$CurrentConnection = @()
foreach ($site in $IISsites)
{
Write-Host $site
$ConnCount = New-Object psobject | get-CurrentConnection -Site $site.name
$CurrentConnection += $ConnCount
}
$CurrentConnection|out-gridview

posh script to get iis user connections number

You can also display the numerical values of connection counters for all sites (the first value is the total number of connections to IIS):

Get-wmiObject -class Win32_PerfRawData_W3SVC_WebService | select-object -expand currentconnections

Get-wmiObject Win32_PerfRawData_W3SVC_WebService currentconnectionsYou can display information about the amount of received/sent data for each site or the entire web server using the Web service(sitename)\Bytes Received/sec and Web service(sitename)\Bytes Sent/sec counters.

So, we looked at a way to get information about the load on sites running on the IIS web server.

4 comments
3
Facebook Twitter Google + Pinterest
previous post
High CPU Usage by Ntoskrnl.exe (System) Process in Windows 10
next post
“Downloading updates 0%” Issue on Windows Server 2016 and Windows 10

Related Reading

Configuring Event Viewer Log Size on Windows

May 24, 2023

How to Detect Who Changed the File/Folder NTFS...

May 24, 2023

Enable Single Sign-On (SSO) Authentication on RDS Windows...

May 23, 2023

Allow Non-admin Users RDP Access to Windows Server

May 22, 2023

How to Create, Change, and Remove Local Users...

May 17, 2023

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Configuring Event Viewer Log Size on Windows

    May 24, 2023
  • How to Detect Who Changed the File/Folder NTFS Permissions on Windows?

    May 24, 2023
  • Enable Single Sign-On (SSO) Authentication on RDS Windows Server

    May 23, 2023
  • Allow Non-admin Users RDP Access to Windows Server

    May 22, 2023
  • How to Create, Change, and Remove Local Users or Groups with PowerShell?

    May 17, 2023
  • Fix: BSOD Error 0x0000007B (INACCESSABLE_BOOT_DEVICE) on Windows

    May 16, 2023
  • View Success and Failed Local Logon Attempts on Windows

    May 2, 2023
  • Fix: “Something Went Wrong” Error When Installing Teams

    May 2, 2023
  • Querying Windows Event Logs with PowerShell

    May 2, 2023
  • Configure Windows LAPS (Local Administrator Passwords Solution) in AD

    April 25, 2023

Follow us

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Active Directory Dynamic User Groups with PowerShell
  • Assign Multiple IP Addresses (Aliases) to a Single NIC
  • How to Measure Storage Performance and IOPS on Windows?
  • How to Get My Public IP Address Using PowerShell
  • Using PowerShell to View and Change BIOS Settings
  • Disks and Partitions Management with Windows PowerShell
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top