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?

May 19, 2021 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

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

4 comments

Sergio Cascales Puerto September 1, 2021 - 2:56 pm

Hello
Error in powershell ise as admin:
PS C:\WINDOWS\system32> 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:SCP-Portatil
}
$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
@{name=Default Web Site}
Get-Counter : Unable to connect to the specified computer or the computer is offline.
At line:3 char:1
+ Get-Counter “web service($Site)\current connections,web service($Site …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
+ FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

Reply
Sergio Cascales Puerto September 1, 2021 - 3:10 pm

If a leave without machine name error say:
@{name=naveotest.istinfor.com}
Get-Counter : The specified counter path could not be interpreted.
At C:\Ageinfo\iisConnections.ps1:3 char:2
+ Get-Counter “web service($Site)\current connections,web service($Sit …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
+ FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

Reply
srinivas November 11, 2021 - 8:56 am

Can we find out each user details how many are logged in. THe question i asked is because there might be chance that a single user can open two – three sessions.

Reply
Javier July 11, 2022 - 3:48 pm

Is there a way to see the current connections per application? I have the main site with 12 apps and want to know which app is hitting more connections, with this I can only get the grand total for the site.

Reply

Leave a Comment Cancel Reply

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

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

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

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


Back To Top