If you need to find out how many concurrent user connections on to your WFE, you need to use the below script. THe script uses Win32_PerfFormattedData_W3SVC_WebService performance Counter to give you exactly how many people are hitting a WFE and will send an email. I have created a scheduled task that runs every hour from 9 ET to 4 ET.
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
#The mail address of who will receive the backup exception message
$from = βspadmin@contoso.comβ
#Send email function
function SendMail($subject, $body)
{
try
{
#Getting SMTP server name and Outbound mail sender address
$caWebApp = (Get-SPWebApplication -IncludeCentralAdministration) | ? { $_.IsAdministrationWebApplication -eq $true }
$smtpServer = $caWebApp.OutboundMailServiceInstance.Server.Address
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
#Creating a Mail object
$message = New-Object System.Net.Mail.MailMessage
$message.Subject = $subject
$message.Body = $body
$To = someone@contoso.com
$message.To.Add($To1)
$message.From = $from
#Creating SMTP server object
#Sending email
$smtp.Send($message)
Write-Host "Email has been Sent!"
}
catch [System.Exception]
{
Write-Host "Mail Sending Error:" $_.Exception.Message -ForegroundColor Red
}
}
$String = ""
$String +="==============================================================================`n"
$String +=" !!!!! Connections Alert !!!!! `n"
$String +="==============================================================================`n"
#Change the value as per need
[system.int32]$Threshold = 100
[System.Boolean]$EmailNeed = $false
Write-Host "Server : Connections"
Write-Host "============================"
$String +="Server : Connections Count`n"
$String +="==============================================================================`n"
$ServerCSV = ""
Get-WmiObject -Class Win32_PerfFormattedData_W3SVC_WebService -ComputerName Server1,Server2,Server3,Server4 | Where {$_.Name -eq "_Total"} | % `
{
$ServerName = $_.__SERVER;
$Connections = $_.CurrentConnections
$String +="$ServerName : $Connections`n"
Write-Host "$ServerName : $Connections"
}
$String +="`n`n==============================================================================`n"
$String +="This is just an alert. Please contact someone@contoso.com for more information.`n"
$Date = Get-Date
SendMail -subject "SharePoint : ! Connections !: Time: $Date" -body $String
Write-Host "Done.."
#Examples of how to find the required Counters
#Get-WmiObject -List | ? Name -like "*NetLogon*"
#Get-WmiObject -List | ? Name -like "*NetLogon*" | Select Name
#Get-WmiObject -List | ? Name -like "*NetLogon*" | Select -ExpandProperty Properties
#Get-WmiObject -Class Win32_PerfFormattedData_Counters_Netlogon -ComputerName Server1,Server2,Server3,Server4 | Where {$_.Name -eq "_Total"} | % {Write-Host $_.__SERVER;Write-Host $_.SemaphoreTimeouts}
Save the above script as GetConnect-FromServes.ps1
Scheduled Task XML
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2015-08-20T15:54:47.5695947</Date>
<Author>Domain\UserName</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<Repetition>
<Interval>PT5M</Interval>
<Duration>P1D</Duration>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2015-08-20T15:52:04.6019445</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>Domain\UserName</UserId>
<LogonType>Password</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
<Arguments>-ExecutionPolicy Bypass E:\Scripts\GetConnect-FromServes.ps1</Arguments>
</Exec>
</Actions>
</Task>
Save the above XML as File and Open the Task in Task Schedule. Change Credentials and Script Locations.
Like this:
Like Loading...
Related