ever wonder how many people connected to your website?
with a usefull cmdlet named : Get-Counter we can query the IIS for getting the total amount of connections ,and we can query it from each website.
get-counter is basically a cmdlet which letting us use all of the Performance Counters installed on our system from the PS Console.
we can run the cmdlet Get-Counter and getting results of counter samples like –
-network interface
-processor
-memory
-disk
we can always make use of it for what we really need ,i would like to know how many connections open to my websites ,so i’m gonna use the counter name “web service(SiteName)\Current Connections”
1 |
Get-Counter "web service($Site)\current connections" -ComputerName $env:COMPUTERNAME |
to make it more usefull we’ll make a script which will get all our running websites on the IIS and query each one of them with its current connections
Important, with this script we’ll use the module of webadministration
1 |
import-module webadministration |
Get Current Connections from IIS websites –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import-module webadministration $sitename = dir IIS:\Sites | Select Name function get-CurrentConnection($Site) { Get-Counter "web service($Site)\current connections" -ComputerName $env:COMPUTERNAME } $CurrentConnection = @() foreach ($Site in $SiteName) { Write-Host $Site $CC = New-Object psobject | get-CurrentConnection -Site $Site.name $CurrentConnection += $cc } $CurrentConnection |
tip: while using get-counter command you can add more servers –
1 |
Get-Counter "web service($Site)\current connections" -ComputerName Web01,Web02 |
Getting Total Connection from all the IIS using the “_total” keyword –
1 |
Get-Counter -Counter 'web service(_total)\current connections' -ComputerName Web01,Web02 |
How could I output this to SQL Table
Exactly the script I needed, thank you.