Introduction

You need to create number of hosts, host instances, adapter handlers for several environments.

The annoying thing is to give the username and password to each and every host instance after creating them is very time consuming. So you need to write PowerShell script to automate this process and it really saved lot of my time. We are logging the BizTalk application level errors to a custom event viewer log and not under “Application” so need to create a new event source for all BizTalk applications. When BizTalk writes the errors to the event viewer it expects the log and source to be created prior to that and BizTalk host account does not have permissions to create the event source and alter the registry. So we are doing this as one time task with higher installer account using PowerShell.

This article explains creating hosts, host instances, adapter handlers and custom event source using PowerShell script.

Details

This sample contains PowerShell scripts for creating hosts, host instances and adapter handlers for different hosts.

Once we create host instances we need to assign specific BizTalk host account and password and isolated account and password. So we can specify the username/password in the PowerShell script and when it runs it automatically assigns the username/password to the host instances.

The numbers of hosts depends on the scenario and we need to decide how many we want before running this script and also rename the host’s names.

This script can be run multiple times on the existing servers as there is logic is to check whether the object exists or not. If it does not exists then only creates the resource.

 

Creating hosts

 

Write-host "Getting Valid Environment name"
  
$PSScriptRoot=Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
  ; 
Write-host "Getting BizMgmtDb Server Name"
$btsConnectionString = "server=.;database=BizTalkMgmtDb;Integrated Security=SSPI";
if ((Test-Path "hklm:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration") -eq $true)
{
 Write-Output "Found registry entry for BizTalk Management DB."
 $btsDBServer = (Get-ItemProperty "hklm:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration").MgmtDBServer
 $btsMgmtDB = (Get-ItemProperty "hklm:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration").MgmtDBName
 $btsConnectionString = "server="+$btsDBServer+";database="+$btsMgmtDB+";Integrated Security=SSPI"
}
  
Write-Host "Loading Powershell provider for BizTalk snap-in"
  
$InitializeDefaultBTSDrive = $false
Add-PSSnapin –Name BizTalkFactory.Powershell.Extensions
  
Write-Host $btsDBServer
  
New-PSDrive -Name BizTalk -Root BizTalk:\ -PsProvider BizTalk -Instance $btsDBServer -Database BizTalkMgmtDb
  
Write-Host "Switch to the default BizTalk drive"
Set-Location –Path BizTalk:
  
Write-Host "Start Checking BizTalk Hosts"
Set-Location -Path 'Platform Settings\Hosts'
  
Write-host "Getting Default BizTalk Applicaton Users Group Name"
$btsApplicationGroupName = Get-ItemProperty -Path 'BizTalkServerApplication' -Name 'NtGroupName'
$btsIsolatedHostGroupName = Get-ItemProperty -Path 'BizTalkServerIsolatedHost' -Name 'NtGroupName'
  
write-host "Check if Receiving Host Exists"
$ReceivingHost = Get-ChildItem | Where-Object{$_.Name -eq "Receiving"}
if($ReceivingHost.Name -eq $null)
{
 Write-Host "Creating Receiving Host"
 New-Item Receiving -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Receiving -Name 'Is32BitOnly' -Value 'True'
}
  
write-host "Check if Receiving_64 Host Exists"
$ReceivingHost = Get-ChildItem | Where-Object{$_.Name -eq "Receiving_64"}
if($ReceivingHost.Name -eq $null)
{
 Write-Host "Creating Receiving_64 Host"
 New-Item Receiving_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Receiving_64 -Name 'Is32BitOnly' -Value 'False'
}
  
write-host "Check if Sending Host Exists"
$SendingHost = Get-ChildItem | Where-Object{$_.Name -eq "Sending"}
if($SendingHost.Name -eq $null)
{
 Write-Host "Creating Sending Host"
 New-Item Sending -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Sending -Name 'Is32BitOnly' -Value 'True'
}
  
write-host "Check if Sending_64 Host Exists"
$Sending_64Host = Get-ChildItem | Where-Object{$_.Name -eq "Sending_64"}
if($Sending_64Host.Name -eq $null)
{
 Write-Host "Creating Sending_64 Host"
 New-Item Sending_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Sending_64 -Name 'Is32BitOnly' -Value 'False'
}
  
write-host "Check if Processing Host Exists"
$ProcessingHost = Get-ChildItem | Where-Object{$_.Name -eq "Processing"}
if($ProcessingHost.Name -eq $null)
{
 Write-Host "Creating Processing Host"
 New-Item Processing -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Processing -Name 'Is32BitOnly' -Value 'True'
}
  
  
write-host "Check if Processing_64 Host Exists"
$Processing_64Host = Get-ChildItem | Where-Object{$_.Name -eq "Processing_64"}
if($Processing_64Host.Name -eq $null)
{
 Write-Host "Creating Processing_64 Host"
 New-Item Processing_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path Processing_64 -Name 'Is32BitOnly' -Value 'False'
}
  
  
write-host "Check if CoreBankingProcessingLowLatency_64 Host Exists"
$CoreBankingProcessingLowLatency_64Host = Get-ChildItem | Where-Object{$_.Name -eq "CoreBankingProcessingLowLatency_64"}
if($CoreBankingProcessingLowLatency_64Host.Name -eq $null)
{
 Write-Host "Creating CoreBankingProcessingLowLatency_64 Host"
 New-Item CoreBankingProcessingLowLatency_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path CoreBankingProcessingLowLatency_64 -Name 'Is32BitOnly' -Value 'False'
}
  
  
write-host "Check if ProcessingLowLatency Host Exists"
$ProcessingLowLatencyHost = Get-ChildItem | Where-Object{$_.Name -eq "ProcessingLowLatency"}
if($ProcessingLowLatencyHost.Name -eq $null)
{
 Write-Host "Creating ProcessingLowLatency Host"
 New-Item ProcessingLowLatency -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path ProcessingLowLatency -Name 'Is32BitOnly' -Value 'False'
}
  
  
write-host "Check if ReceivingLowLatency_64 Host Exists"
$ReceivingLowLatency_64Host = Get-ChildItem | Where-Object{$_.Name -eq "ReceivingLowLatency_64"}
if($ReceivingLowLatency_64Host.Name -eq $null)
{
 Write-Host "Creating ReceivingLowLatency_64 Host"
 New-Item ReceivingLowLatency_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path ReceivingLowLatency_64 -Name 'Is32BitOnly' -Value 'False'
}
  
write-host "Check if SendingLowLatency_64 Host Exists"
$SendingLowLatency_64Host = Get-ChildItem | Where-Object{$_.Name -eq "SendingLowLatency_64"}
if($SendingLowLatency_64Host.Name -eq $null)
{
 Write-Host "Creating SendingLowLatency_64 Host"
 New-Item SendingLowLatency_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path SendingLowLatency_64 -Name 'Is32BitOnly' -Value 'False'
}
  
write-host "Check if OriginationsProcessingLowLatency_64 Host Exists"
$OriginationsProcessingLowLatency_64Host = Get-ChildItem | Where-Object{$_.Name -eq "OriginationsProcessingLowLatency_64"}
if($OriginationsProcessingLowLatency_64Host.Name -eq $null)
{
 Write-Host "Creating OriginationsProcessingLowLatency_64 Host"
 New-Item OriginationsProcessingLowLatency_64  -NtGroupName $btsApplicationGroupName.NtGroupName -HostType 'InProcess'
 Set-ItemProperty -Path OriginationsProcessingLowLatency_64 -Name 'Is32BitOnly' -Value 'False'
}
  
write-host "Check if CoreBankingBizTalkServerIsolatedHost Host Exists"
$CoreBankingBizTalkServerIsolatedHostHost = Get-ChildItem | Where-Object{$_.Name -eq "CoreBankingBizTalkServerIsolatedHost"}
if($CoreBankingBizTalkServerIsolatedHostHost.Name -eq $null)
{
 Write-Host "Creating CoreBankingBizTalkServerIsolatedHost Host"
 New-Item CoreBankingBizTalkServerIsolatedHost -NtGroupName 'TWGFS\.TWGFS_BTS_Staging_Isolated_Host_ Users' -HostType 'Isolated'
 Set-ItemProperty -Path CoreBankingBizTalkServerIsolatedHost -Name 'Is32BitOnly' -Value 'False'
}
Write-Host "End Checking BizTalk Hosts"

 

Creating Host Instances

 

Write-Host "Start Checking BizTalk Host Instances"
Set-location -Path ..\'Host Instances'
$HostPassword = ConvertTo-SecureString -String "hostpassword" -AsPlainText -Force
$HostisoPassword = ConvertTo-SecureString -String "hostisopassword" -AsPlainText -Force
$HostCredentials = New-Object -TypeName:System.Management.Automation.PSCredential -ArgumentList 'domain\hostuser', $HostPassword
$HostisoCredentials = New-Object -TypeName:System.Management.Automation.PSCredential -ArgumentList 'domain\hostisouser', $HostisoPassword
write-host "Check if Receiving Host Instance exists"
$ReceivingHostInstance = get-ChildItem |Where-Object{$_.Name -like "Receiving"}
if($ReceivingHostInstance.Name -eq $null)
{
 Write-Host "Creating Receiving Host Instance"
 New-Item -Path:'HostInstance' -HostName:Receiving -Credentials:$HostCredentials
}
  
  
write-host "Check if Receiving_64 Host Instance exists"
$Receiving_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "Receiving_64"}
if($Receiving_64HostInstance.Name -eq $null)
{
 Write-Host "Creating Receiving_64 Host Instance"
 New-Item -Path:'HostInstance' -HostName:Receiving_64 -Credentials:$HostCredentials
}
  
write-host "Check if Sending Host Instance exists"
$SendingHostInstance = get-ChildItem |Where-Object{$_.Name -like "Sending"}
if($SendingHostInstance.Name -eq $null)
{
 Write-Host "Creating Sending HostInstance"
 New-Item -Path:'HostInstance' -HostName:Sending -Credentials:$HostCredentials
}
  
write-host "Check if Sending_64 Host Instance exists"
$Sending_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "Sending_64"}
if($Sending_64HostInstance.Name -eq $null)
{
 Write-Host "Creating Sending_64 HostInstance"
 New-Item -Path:'HostInstance' -HostName:Sending_64 -Credentials:$HostCredentials
}
  
write-host "Check if Processing Host Instance exists"
$ProcessingHostInstance = get-ChildItem |Where-Object{$_.Name -like "Processing"}
if($ProcessingHostInstance.Name -eq $null)
{
 Write-Host "Creating Processing HostInstance"
 New-Item -Path:'HostInstance' -HostName:Processing -Credentials:$HostCredentials
}
  
write-host "Check if Processing_64 Host Instance exists"
$Processing_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "Processing_64"}
if($Processing_64HostInstance.Name -eq $null)
{
 Write-Host "Creating Processing_64 HostInstance"
 New-Item -Path:'HostInstance' -HostName:Processing_64 -Credentials:$HostCredentials
}
write-host "Check if CoreBankingProcessingLowLatency_64 Host Instance exists"
$CoreBankingProcessingLowLatency_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "CoreBankingProcessingLowLatency_64"}
if($CoreBankingProcessingLowLatency_64HostInstance.Name -eq $null)
{
 Write-Host "Creating CoreBankingProcessingLowLatency_64 HostInstance"
 New-Item -Path:'HostInstance' -HostName:CoreBankingProcessingLowLatency_64 -Credentials:$HostCredentials
}
  
  
write-host "Check if ProcessingLowLatency Host Instance exists"
$ProcessingLowLatencyHostInstance = get-ChildItem |Where-Object{$_.Name -like "ProcessingLowLatency"}
if($ProcessingLowLatencyHostInstance.Name -eq $null)
{
 Write-Host "Creating ProcessingLowLatency HostInstance"
 New-Item -Path:'HostInstance' -HostName:ProcessingLowLatency -Credentials:$HostCredentials
}
  
write-host "Check if SendingLowLatency_64 Host Instance exists"
$SendingLowLatency_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "SendingLowLatency_64"}
if($SendingLowLatency_64HostInstance.Name -eq $null)
{
 Write-Host "Creating SendingLowLatency_64 HostInstance"
 New-Item -Path:'HostInstance' -HostName:SendingLowLatency_64 -Credentials:$HostCredentials
}
  
write-host "Check if OriginationsProcessingLowLatency_64 Host Instance exists"
$OriginationsProcessingLowLatency_64HostInstance = get-ChildItem |Where-Object{$_.Name -like "OriginationsProcessingLowLatency_64"}
if($OriginationsProcessingLowLatency_64HostInstance.Name -eq $null)
{
 Write-Host "Creating OriginationsProcessingLowLatency_64 HostInstance"
 New-Item -Path:'HostInstance' -HostName:OriginationsProcessingLowLatency_64 -Credentials:$HostCredentials
}
  
write-host "Check if CoreBankingBizTalkServerIsolatedHost Host Instance exists"
$CoreBankingBizTalkServerIsolatedHostHostInstance = get-ChildItem |Where-Object{$_.Name -like "CoreBankingBizTalkServerIsolatedHost"}
if($CoreBankingBizTalkServerIsolatedHostHostInstance.Name -eq $null)
{
 Write-Host "Creating CoreBankingBizTalkServerIsolatedHost HostInstance"
 New-Item -Path:'HostInstance' -HostName:CoreBankingBizTalkServerIsolatedHost -Credentials:$HostisoCredentials
}
Write-Host "End Checking BizTalk Host Instances"

 

Creating Adapter Handlers

Write-Host "Start Checking File Handlers are present"
Set-Location -Path '..\Adapters'
Set-Location –Path 'FILE'
$Receiving64FILEHandler = Get-ChildItem | Where-Object{$_.Name -eq "FILE Receive Handler (Receiving_64)"}
if($Receiving64FILEHandler.Name -eq $null)
{
 Write-Host "Adding FILE Receive handler for Receiving_64 Host"
 New-Item -Path .\Receiving_64 -HostName Receiving_64 -Direction Receive
}
$Sending_64FILEHandler = Get-ChildItem | Where-Object{$_.Name -eq "FILE Send Handler (Sending_64)"}
if($Sending_64FILEHandler.Name -eq $null)
{
 Write-Host "Adding FILE Send handler for Sending_64 Host"
 New-Item -Path .\Sending_64 -HostName Sending_64 -Direction Send
}
Write-Host "End of Checking FILE Handlers are present"
  
Write-Host "Switch to WCF-CustomIsolated Adapter drive"
Set-Location –Path '..\WCF-CustomIsolated'
$CoreBankingBizTalkServerIsolatedHostBasicHttpHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-CustomIsolated Receive Handler (CoreBankingBizTalkServerIsolatedHost)"}
if($CoreBankingBizTalkServerIsolatedHostBasicHttpHandler.Name -eq $null)
{
 Write-Host "Adding WCF-CustomIsolated Receive handler for CoreBankingBizTalkServerIsolatedHost Host"
 New-Item -Path .\CoreBankingBizTalkServerIsolatedHost -HostName CoreBankingBizTalkServerIsolatedHost -Direction Receive
}
Write-Host "End of Checking WCF-CustomIsolated Handlers are present"
  
Write-Host "Switch to WCF-WebHttp Adapter drive"
Set-Location –Path '..\WCF-WebHttp'
$SendingLowLatency_64WebHttpHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-WebHttp Send Handler (SendingLowLatency_64)"}
if($SendingLowLatency_64WebHttpHandler.Name -eq $null)
{
 Write-Host "Adding WCF-WebHttp Send handler for SendingLowLatency_64 Host"
 New-Item -Path .\SendingLowLatency_64 -HostName SendingLowLatency_64 -Direction Send
}
Write-Host "End of Checking WCF-BasicHttp Handlers are present"
  
Write-Host "Switch to WCF-WSHttp Adapter drive"
Set-Location –Path '..\WCF-WSHttp'
$SendingLowLatency_64WSHttpHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-WSHttp Send Handler (SendingLowLatency_64)"}
if($SendingLowLatency_64WSHttpHandler.Name -eq $null)
{
 Write-Host "Adding WCF-WSHttp Send handler for SendingLowLatency_64 Host"
 New-Item -Path .\SendingLowLatency_64 -HostName SendingLowLatency_64 -Direction Send
}
$BizTalkServerIsolatedHostWSHttpHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-WSHttp Receive Handler (BizTalkServerIsolatedHost)"}
if($BizTalkServerIsolatedHostWSHttpHandler.Name -eq $null)
{
 Write-Host "Adding WCF-WSHttp Send handler for BizTalkServerIsolatedHost"
 New-Item -Path .\BizTalkServerIsolatedHost -HostName BizTalkServerIsolatedHost -Direction Receive
}
Write-Host "End of Checking WCF-BasicHttp Handlers are present"
  
Write-Host "Switch to SFTP Adapter drive"
Set-Location –Path '..\SFTP'
$Sending_64SFTPHandler = Get-ChildItem | Where-Object{$_.Name -eq "SFTP Send Handler (Sending_64)"}
if($Sending_64SFTPHandler.Name -eq $null)
{
 Write-Host "Adding SFTP Send handler for Sending_64 Host"
 New-Item -Path .\Sending_64 -HostName Sending_64 -Direction Send
}
$Receiving_64SFTPHandler = Get-ChildItem | Where-Object{$_.Name -eq "SFTP Receive Handler (Receiving_64)"}
if($Receiving_64SFTPHandler.Name -eq $null)
{
 Write-Host "Adding SFTP Receive handler for Receiving_64 Host"
 New-Item -Path .\Receiving_64 -HostName Receiving_64 -Direction Receive
}
Write-Host "End of Checking SFTP Handlers are present"
Write-Host "Switch to FTP Adapter drive"
Set-Location –Path '..\FTP'
$ReceivingFTPHandler = Get-ChildItem | Where-Object{$_.Name -eq "FTP Receive Handler (Receiving)"}
if($ReceivingFTPHandler.Name -eq $null)
{
 Write-Host "Adding FTP Receive handler for Receiving Host"
 New-Item -Path .\Receiving -HostName Receiving -Direction Receive
}
$SendingFTPHandler = Get-ChildItem | Where-Object{$_.Name -eq "FTP Send Handler (Sending)"}
if($SendingFTPHandler.Name -eq $null)
{
 Write-Host "Adding FTP Send handler for Sending Host"
 New-Item -Path .\Sending -HostName Sending -Direction Send
}
Write-Host "End of Checking FTP Handlers are present"
  
  
Write-Host "Switch to ScheduleTask Adapter drive"
Set-Location –Path '..\ScheduleTask'
$ScheduleTaskHandler = Get-ChildItem | Where-Object{$_.Name -eq "ScheduleTask Receive Handler (Receiving)"}
if($ScheduleTaskHandler.Name -eq $null)
{
 Write-Host "Adding ScheduleTask Receive handler for Receiving Host"
 New-Item -Path .\ScheduleTask -HostName Receiving -Direction Receive
}
  
Write-Host "End of Checking ScheduleTask Handlers are present"
  
  
Write-Host "Start Checking WCF-Custom Handlers are present"
Write-Host "Switch to WCF-Custom Adapter drive"
Set-Location -Path '..\WCF-Custom'
  
$SendingLowLatency_64WCFCustomHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-Custom Send Handler (SendingLowLatency_64)"}
if($SendingLowLatency_64WCFCustomHandler.Name -eq $null)
{
 Write-Host "Adding WCF-Custom Sending handler for SendingLowLatency_64 Host"
 New-Item -Path .\SendingLowLatency_64 -HostName SendingLowLatency_64 -Direction Send
}
  
$Sending_64WCFCustomHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-Custom Send Handler (Sending_64)"}
if($Sending_64WCFCustomHandler.Name -eq $null)
{
 Write-Host "Adding WCF-Custom Sending handler for Sending_64 Host"
 New-Item -Path .\Sending_64 -HostName Sending_64 -Direction Send
}
$Receiving_64WCFCustomHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-Custom Receive Handler (Receiving_64)"}
if($Receiving_64WCFCustomHandler.Name -eq $null)
{
 Write-Host "Adding WCF-Custom Receiving handler for Receiving_64 Host"
 New-Item -Path .\Receiving_64 -HostName Receiving_64 -Direction Receive
}
  
Write-Host "End of Checking WCF-Custom Handlers are present"
  
Write-Host "Start Checking WCF-SQL Handlers are present"
Write-Host "Switch to WCF-SQL Adapter drive"
Set-Location -Path '..\WCF-SQL'
$Receiving_64WCFSQLHandler = Get-ChildItem | Where-Object{$_.Name -eq "WCF-SQL Receive Handler (Receiving_64)"}
if($Receiving_64WCFSQLHandler.Name -eq $null)
{
 Write-Host "Adding WCF-SQL Receiving handler for Receiving_64 Host"
 New-Item -Path .\Receiving_64 -HostName Receiving_64 -Direction Receive
}
Write-Host "End of Checking WCF-SQL Handlers are present"
  
Write-Host "Start Checking SB-Messaging Handlers are present"
Write-Host "Switch to SB-Messaging Adapter drive"
Set-Location -Path '..\SB-Messaging'
$Receiving_64SBMessagingHandler = Get-ChildItem | Where-Object{$_.Name -eq "SB-Messaging Receive Handler (Receiving_64)"}
if($Receiving_64SBMessagingHandler.Name -eq $null)
{
 Write-Host "Adding SB-Messaging Receiving handler for Receiving_64 Host"
 New-Item -Path .\Receiving_64 -HostName Receiving_64 -Direction Receive
}
$Sending_64SBMessagingHandler = Get-ChildItem | Where-Object{$_.Name -eq "SB-Messaging Send Handler (Sending_64)"}
if($Sending_64SBMessagingHandler.Name -eq $null)
{
 Write-Host "Adding SB-Messaging Sending handler for Sending_64 Host"
 New-Item -Path .\Sending_64 -HostName Sending_64 -Direction Send
}
Write-Host "End of Checking WCF-SQL Handlers are present"

 

Create custom event log and source

 

#set permissions for the event log; read and write to the EventLog key and its subkeys and values.
$acl= get-acl -path "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog"
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$rule=new-object system.security.accesscontrol.registryaccessrule "Authenticated Users","FullControl",$inherit,$propagation,"Allow"
$acl.addaccessrule($rule)
$acl|set-acl
  
#create the Event Log
$EventLogName = "BizTalk"
$EventLogSource = "TWGFS.Core.BizTalk"
$EventLogSource1 = "TWGFS.Core.BizTalk.PreProcessor"
$EventLogSource2 = "TWGFS.Core.BizTalk.DiscountsLoyalty"
  
$EventLogExists = Get-EventLog -list | Where-Object {$_.logdisplayname -eq $EventLogName}
  
if (! $EventLogExists) {
New-EventLog -LogName $EventLogName -Source $EventLogSource -ErrorAction Ignore| Out-Null 
 Write-EventLog -LogName $EventLogName -Source $EventLogSource -Message "Creating Event Log $EventLogName" -EventId 0 -EntryType information
 New-EventLog -LogName $EventLogName -Source $EventLogSource1 -ErrorAction Ignore| Out-Null
 Write-EventLog -LogName $EventLogName -Source $EventLogSource1 -Message "Creating Event Log $EventLogName" -EventId 0 -EntryType information
 New-EventLog -LogName $EventLogName -Source $EventLogSource2 -ErrorAction Ignore| Out-Null
Write-EventLog -LogName $EventLogName -Source $EventLogSource2 -Message "Creating Event Log $EventLogName" -EventId 0 -EntryType information
Write-Host "If you have Event Viewer open, you should probably close and reopen it."
Get-EventLog -list
}
else{
Write-Host "There is already an '$EventLogName' event log"
Write-EventLog -LogName $EventLogName -Source $EventLogName -Message "Hello Event Log $EventLogName" -EventId 0 -EntryType information
}

Running the Samples

Go to TechNet gallery and download the two PowerShell scripts

https://code.msdn.microsoft.com/Powershell-for-creating-86efbd2d

CreateBiztalkHostsAndHostInstances_V2.ps1

Create_EventLog.ps1

Running Hosts creation script

 Open CreateBiztalkHostsAndHostInstances_V2.ps1 in PowerShell editor or notepad

And navigate to the below code

 

Write-Host "Start Checking BizTalk Host Instances"
Set-location -Path ..\'Host Instances'
$HostPassword = ConvertTo-SecureString -String "hostpassword" -AsPlainText -Force
$HostisoPassword = ConvertTo-SecureString -String "hostisopassword" -AsPlainText -Force
$HostCredentials = New-Object -TypeName:System.Management.Automation.PSCredential -ArgumentList 'domain\hostuser', $HostPassword
$HostisoCredentials = New-Object -TypeName:System.Management.Automation.PSCredential -ArgumentList 'domain\hostisouser', $HostisoPassword

Replace

Hostpassword with actual password of the host account

Hostisopassword with actual password of the isolated host account

domain\hostuser with host account

domain\hostisouser with isolated host account

After charging the above stuff save the file to the same location.

Open the PowerShell ISE window as administrator and check the permissions to run the script

Type the below command and press enter

Get-ExecutionPolicy

If the window displays “RemoteSigned” then we need to set the permissions to “Unrestricted” and run the scripts. Once the execution is over we need revert the permissions to “RemoteSigned”

You can alter the permissions using the below command and press enter

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

A pop windows appears and select “Yes”

And then type the path of the file

 

Once the execution is over then reset the permissions to Remote Signed.

 

 

Running Event log source script

Open Create_EventLog.ps1 in PowerShell editor or notepad and navigate to the below code

Please change the below names to the name of BizTalk applications. Here we have 3 BizTalk applications writing the errors to event viewer so we are creating 3 event sources and a common BizTalk event viewer log.

#create the Event Log
$EventLogName = "BizTalk"
$EventLogSource = "TWGFS.Core.BizTalk"
$EventLogSource1 = "TWGFS.Core.BizTalk.PreProcessor"
$EventLogSource2 = "TWGFS.Core.BizTalk.DiscountsLoyalty"

After running these scripts we can see the below in event viewer.

 

Under Applications and Services Logs we can see new “BizTalk” log created

Conclusion

Hope this article helps to bulk create number of hosts, hosts instances, adapter handlers and custom event log on different servers and the beauty of the script is we can run this multiple times on existing server.

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.