Tuesday 3 June 2014

Tweak IIS for Service Manager 2012 Self Service Portal

It's been known for some time that the Self Service Portal in Service Manager can sometimes be rather slow.

This is usually when a user hasn't used it for a while (Usually seen in demo environments) and periodically it will grind for a while.

Travis blogged about some tweaks to IIS centred around the Application Pool and recycling timeouts some time back.

With the amount of scripting I've been doing lately, I thought I'd share a little snippet of PowerShell that can be used to set IIS on your SSP to tweak these settings for a bit more performance.

<#
 .Notes
 NAME: Tune-SCSMPortal.ps1
 AUTHOR: Steve Beaumont
 Website: http://systemscentre.blogspot.com
 Twitter: http://twitter.com/stevybsc
 Version: 1.0
 CREATED: 03/06/2014
 LASTEDIT:
 03/06/2014 1.0
 Initial Release

 .Synopsis
 Tweaks IIS settings for better performance of the System Center 2012 R2 Service Manager Self Service Portal

 .Description
 Alters the configuration settings for the System Center 2012 R2 Service Manager Self Service Portal App Pool to disable periodic recycling and increase the number of worker processes

 .Parameter SCSMPortalServer
 Specify a remote server to connect to and run the tweaks.  If not specified the script will run on the local host.

 .Parameter AppPoolName
 Specify a different App Pool name to tweak. If not specified the default SCSM app name of "Service Manager Portal" will be used.

 .Parameter SiteName
 Specify a different IIS Site name to tweak. If not specified the default SCSM site name of "Service Manager Portal" will be used.
 
 .Outputs
 [ref]
 None.

 .Example
 .\Tune-SCSPortal.ps1

 .Example
 .\Tune-SCSPortal.ps1 -SCSMPortalServer PONSCSM05

  .Example
 .\Tune-SCSPortal.ps1 -SCSMPortalServer PONSCSM05 -AppPoolName "SCSM Pool"

  .Example
 .\Tune-SCSPortal.ps1 -SCSMPortalServer PONSCSM05 -SiteName "Service Desk"

 .Example
 .\Tune-SCSPortal.ps1 -SCSMPortalServer PONSCSM05 -AppPoolName "SCSM Pool" -SiteName "Service Desk"

#>

[Cmdletbinding()]  
Param (   
    [Parameter(Mandatory=$false)]
    [String]$SCSMPortalServer=".",
    [Parameter(Mandatory=$false)]
    [String]$AppPoolName="Service Manager Portal",
    [Parameter(Mandatory=$false)]
    [String]$SiteName="Service Manager Portal"
    )

Invoke-Command -ComputerName $SCSMPortalServer -ScriptBlock {
 If (!(Get-Module WebAdministration)) {Import-Module WebAdministration}
    Write-Output "*Current App Pool settings*"
    Write-Output "---------------------------"
    Write-Output "Periodic Restart:"
    Get-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name Recycling.periodicRestart.time.value
    Write-Output "Idle Timeout:"
 Get-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name processModel.idleTimeout.value
    Write-Output "Max Worker Processes:"
 Get-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name processModel.maxProcesses.value
    
    Write-Output ""
 Write-Output "Configuring App Pool settings for better performance..."
    Set-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name Recycling.periodicRestart.time -value ([TimeSpan]::FromMinutes(0))
 Set-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name processModel.idleTimeout -value ([TimeSpan]::FromMinutes(0))
 [int]$CPU=(Get-WmiObject -namespace "root\CIMV2" -class Win32_Processor -Property NumberOfCores).NumberOfCores
 Set-ItemProperty -Path "IIS:\AppPools\$Using:AppPoolName" -Name processModel.maxProcesses -value $CPU
    Set-WebConfigurationProperty "/system.applicationHost/sites/site[@name=`"$Using:SiteName`"]" -PSPath IIS:\ -Name LogFile -Value (@{enabled=$false})

    Write-Output ""
    Write-Output "Restarting IIS"
 IISRESET
 }


Not the easiest to read via this blog, so I've added a more polished version to the TechNet Gallery here:
http://gallery.technet.microsoft.com/Tune-IIS-for-System-Center-ed002b87