Monday, November 4, 2013

Slow SharePoint Start Up - Disable CLR Check with PowerShell

If you are experiencing slow SharePoint Application Pool Start Up, probably what you need is to remove CLR Check for Assembly Signing.

I've found a very usefull PowerShell script from marvelous AutoSPInstaller (https://autospinstaller.codeplex.com/) that do it for you.

This function disable CLR Check from Windows Registry and from machine.config.

Here's the snippet:

Function DisableCRLCheck()
{
 Write-Host -ForegroundColor White " - Disabling Certificate Revocation List (CRL) check..."
 Write-Host -ForegroundColor White "  - Registry..."
 New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null
 New-ItemProperty -Path "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -PropertyType DWord -Value 146944 -Force | Out-Null
 New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -Name State -PropertyType DWord -Value 146944 -Force | Out-Null
 Write-Host -ForegroundColor White "  - Machine.config..."
 ForEach($bitsize in ("","64"))
 {
  # Added a check below for $xml because on Windows Server 2012 machines, the path to $xml doesn't exist until the .Net Framework is installed, so the steps below were failing
  $xml = [xml](Get-Content "$env:windir\Microsoft.NET\Framework$bitsize\v2.0.50727\CONFIG\Machine.config" -ErrorAction SilentlyContinue)
  if ($xml)
  {
   If (!$xml.DocumentElement.SelectSingleNode("runtime")) {
    $runtime = $xml.CreateElement("runtime")
    $xml.DocumentElement.AppendChild($runtime) | Out-Null
   }
   If (!$xml.DocumentElement.SelectSingleNode("runtime/generatePublisherEvidence")) {
    $gpe = $xml.CreateElement("generatePublisherEvidence")
    $xml.DocumentElement.SelectSingleNode("runtime").AppendChild($gpe) | Out-Null
   }
   $xml.DocumentElement.SelectSingleNode("runtime/generatePublisherEvidence").SetAttribute("enabled","false") | Out-Null
   $xml.Save("$env:windir\Microsoft.NET\Framework$bitsize\v2.0.50727\CONFIG\Machine.config")
  }
  else
  {
   if ($bitsize -eq "") {$bitsize = "32"}
   Write-Warning "$bitsize-bit machine.config not found - could not disable CRL check."
  }
 }
 Write-Host -ForegroundColor White " - Done."
}


Thanks again to autospinstaller for his wanderfull job.

No comments: