Skip to content

Instantly share code, notes, and snippets.

[System.Reflection.Assembly]::loadwithPartialName("Microsoft.BizTalk.ExplorerOM")
## - Force 32-bit mode, BizTalk.ExplorerOM does NOT support 64-bit mode
if ($env:Processor_Architecture -ne "x86")
{
write-warning "Running x86 PowerShell..."
if ($myInvocation.Line)
{
&"$env:WINDIR\syswow64\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
}
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$Catalog.ConnectionString = "SERVER=xxxxx;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"
foreach($port in $catalog.SendPorts)
{
$portname = $port.name
$portapplication = $port.application.name
$portstatus = $port.status
Write-Host "Name: $portname App: $portapplication Status: $portstatus"
}
foreach($port in $catalog.ReceivePorts)
{
foreach ($location in $port.ReceiveLocations)
{
$rxlocation = $port.ReceiveLocations
$locationname = $location.name
$locationapplication = $port.application.name
$locationstatus = $location.Enable
}
}
foreach($application in $catalog.Applications)
{
foreach ($orchestration in $application.Orchestrations)
{
$AppName = $application.Name
$OrchName = $orchestration.FullName
$OrchApp = $orchestration.Application
$OrchHost = $orchestration.Host
$OrchStatus = $orchestration.Status
}
$hostInstances = get-wmiobject MSBTS_HostInstance -namespace 'root\MicrosoftBizTalkServer' | where {$_.runningserver -match $yourBTServerName}
foreach ($hostInstance in $hostInstances)
{
$hostInstanceName = $hostInstance.hostname
$hostInstanceServer = $hostInstance.RunningServer
#Checks the host instance state
switch ($HostInstance.ServiceState)
{
1 {$state = "Stopped"}
$SqlQuery =`
"SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SET deadlock_priority LOW
SELECT
nvcName AS ApplicationName,
uidInstanceID AS InstanceID,
nErrorCategory,
DATEADD(hh,-5,dtSuspendTimeStamp) AS DateSuspended, -- Subtract the appropriate hours for your timezone
nvcAdapter AS Adapter,
@bat2001
bat2001 / gist:6465222
Last active December 22, 2015 11:19
PowerShell SQL Setup
$SQLServer = 'yourBizTalkSQLServer'
$SQLDBName = 'BizTalkMsgBoxDb'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
$SqlConnection.Open()
# Create SqlCommand object, define command text, and set the connection
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$arrInstancesSuspended = @()
foreach ($Row in $DataSet1.Tables[0].Rows)
{
$arrInstancesSuspended = $arrInstancesSuspended + (,($Row["ApplicationName"],$Row["InstanceID"]))
# Use format: $arrInstancesSuspended [0][0]
}
# Sort Array
$arrInstancesSuspended = $arrInstancesSuspended | Sort-Object @{Expression={$_[0]};Ascending=$true}
# Get unique apps
$unique_Application = $arrInstancesSuspended | foreach {$_[0]} | sort-object -unique
@bat2001
bat2001 / gist:8247385
Created January 3, 2014 21:54
XML change namespace on Xml.XmlDocument in C#
System.Xml.XmlDocument XMLOriginalDoc = new XmlDocument();
System.Xml.XmlDocument XMLFinalDoc = new XmlDocument();
// load an xml document with namespace to be changed. This example loads it from a file
XMLOriginalDoc.Load(openFileDialog1.FileName);
// Now load original document into new document, and modify namespace in the new document
XMLFinalDoc.LoadXml(XMLOriginalDoc.OuterXml.Replace(XMLOriginalDoc.DocumentElement.NamespaceURI, "http://MyNewNamespace"));
@bat2001
bat2001 / gist:99adf2444a7455aa5e8a
Created October 10, 2014 16:27
powershell SQLPSX command to get BizTalk performance counters
Get-PerfCounterCategory | where {$_.Category_Name -like '*BizTalk*'} | Get-PerfCounterInstance | Get-PerfCounterCounters | Format-List Machine_Name,Category_Name,Counter_Name,Counter_Type,Counter_Help | Out-File c:\myouput.txt