Skip to content

Instantly share code, notes, and snippets.

Created May 23, 2014 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c87dc2b8c5a649ad5749 to your computer and use it in GitHub Desktop.
Save anonymous/c87dc2b8c5a649ad5749 to your computer and use it in GitHub Desktop.
Recreate BizTalk Performance counters after upgrade to BizTalk 2013
param([Switch]$Fix, [Switch]$Verbose)
<#
During our testing of in-place upgrades of BizTalk 2010 to BizTalk 2013 we've seen performance counters disappear (especially the BizTalk:Message Agent and BizTalk:Messaging counters).
Inspired by:
• http://blogs.msdn.com/b/biztalkperformance/archive/2007/09/30/how-to-manually-recreate-missing-biztalk-performance-counters.aspx
• http://blogs.msdn.com/b/biztalkcpr/archive/2010/06/23/have-you-manually-recreated-the-biztalk-performance-counter-using-the-following-link-but-some-of-the-counters-were-still-missing.aspx
This script ca fix the issue by:
1. Copying the BTSPerfMonExt.ini and BTSPerfMonExt.h files to the %windir%\system32 folder.
2. Execute the following command to uninstall the damaged performance counters.
unlodctr "BTSSvc.3.0"
3. Then, execute this to reinstall the BizTalk performance counters:
lodctr BTSPerfMonExt.ini
4. Finally fix potentially missing registry keys
#>
$servicesKeyRoots = @("Registry::HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services","Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services")
$BizTalkInstallPath = (Get-ItemProperty "hklm:\SOFTWARE\Microsoft\BizTalk Server\3.0\").InstallPath
$performanceKeyRelativePath = "\BTSSvc.3.0\Performance\"
function Fix-PerformanceCounters
{
Param(
[Parameter(Mandatory=$true)]
[string]$ServicesKeyRoot,
[bool] $Fix,
[bool] $IncludeDetails
)
$performanceKeyRoot = $ServicesKeyRoot + $performanceKeyRelativePath
$hostInstanceInformation = @{}
Get-ChildItem -Path $ServicesKeyRoot |
?{$_.Name.Contains("BTSSvc$")}|
foreach{
$null = ($_.GetValue("ImagePath") -match '\".+\"\s\-group\s\"(.+)\"\s\-name\s\"(.+)\"\s\-btsapp\s\"(.+)\"')
$hostInstanceInformation.Add($matches[3],$matches[1..3])
}
$hostInstanceInformation.Keys |
foreach{
$key = $performanceKeyRoot + $_
$keyExists = Test-Path($key)
if(-not ($keyExists))
{
Set-Variable issuesIdentified $true -scope global
#[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\BTSSvc.3.0\Performance\{1B7F174B-C048-44E9-94F1-A0C8125E8981}]
#"GroupName"="BizTalk Group"
#"AppName"="Tracking_Host"
$appName = $hostInstanceInformation[$_][1]
$groupName = $hostInstanceInformation[$_][0]
write-host ("Host instance (" + $appName + ") missing as key " + $key) -ForegroundColor Magenta
if($Fix)
{
Write-Host ("Creating host instance (" + $appName + ") as key " + $key) -ForegroundColor Green
$null = New-Item -Path $key
Write-Host ("Setting property GroupName to " + $groupName + " below key " + $key) -ForegroundColor Green
$null = Set-ItemProperty -Path $key -Name GroupName -Value $groupName
Write-Host ("Setting property AppName to " + $AppName + " below key " + $key) -ForegroundColor Green
$null = Set-ItemProperty -Path $key -Name AppName -Value $appName
}
}
else
{
if($IncludeDetails)
{
$hostInstanceInformation[$_][1] + " is already defined beneath key " + $key
}
}
}
}
if(-not (Test-Path $BizTalkInstallPath))
{
"BizTalk installation path " + $BizTalkInstallPath + " not found"
Exit-PSSession
}
Push-Location
if($Fix)
{
Copy-Item -Path ($BizTalkInstallPath + "\BTSPerfMonExt.ini") -Destination ($env:SystemRoot + '\system32\')
Copy-Item -Path ($BizTalkInstallPath + "\BTSPerfMonExt.h") -Destination ($env:SystemRoot + '\system32\')
Set-Location ($env:SystemRoot + '\system32\')
unlodctr "BTSSvc.3.0"
lodctr BTSPerfMonExt.ini
}
Set-Variable issuesIdentified $false -scope global
foreach($root in $servicesKeyRoots)
{
Fix-PerformanceCounters -ServicesKeyRoot $root -Fix $Fix -IncludeDetails $Verbose
}
if(-not $Fix -and $issuesIdentified)
{
Write-Host "Issues identified. These can be fixed by providing the -Fix switch" -ForegroundColor Red
}
if(-not $Fix -and -not $issuesIdentified)
{
Write-Host "No issues identified. Providing the -Fix switch will still reinstall the counters" -ForegroundColor Green
}
if($Fix -and -not $issuesIdentified)
{
Write-Host "No issues identified." -ForegroundColor Green
}
Pop-Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment