Introduction
This project documents the usage of PowerShell scripts which can be used for starting and stopping Windows Services, in this particular case TIBCO ActiveMatrix BusinessWorks services which are also having a related TIBCO ActiveMatrix Adapter for SAP services service.
The scripts used for this are also maintained by this project.
Context and History
Most of us probably experienced it multiple times already…
A maintenance window is scheduled at your company and you are required to stop your specific interface related components during the maintenance window and start it once it is completed.
When doing this all manual, it will be a time consuming activity, so we decided to spent some time on writing a PowerShell script which does the work for you and will save you a lot of time and effort for future maintenance windows.
Scripts
2 scripts are maintained in the project :
- SAP_BW_Manual_Stop.ps1
- SAP_BW_Automatic_Start.ps1
In both scripts the code for grabbing the correct services is identical.
Below explanation of the code based on one example interface.
In the screenshot above you can see that there is a specific naming convention in both the TIBCO ActiveMatrix BusinessWorks services and related TIBCO ActiveMatrix Adapter for SAP. The identifier in this case is the value IS0026, this is called the InterfaceID.
The below code snippet will find all services for TIBCO ActiveMatrix Adapter for SAP and deduct the InterfacesID (ex : IS0026) from it.
# Flush InterfaceIDs variable
$InterfaceIDs=@()
# Get all the windows services for SAP Adapters Name and DisplayName
$R3SAP = Get-WmiObject win32_service | Select Name, DisplayName |
Where-Object {$_.displayName.StartsWith("TIBCO ActiveMatrix Adapter for SAP")} |
Sort DisplayName, Name
# Loop trough the SAP services and deduct the interfaceID
$R3SAP | ForEach-Object –Process {
$entry = $_ | Select-Object -Property Interface
$entry.Interface = (($_.Name -split '\.')[1]).SubString(0,6)
$InterfaceIDs = $InterfaceIDs + $entry.Interface
}
# Get the Unique Interface IDs
$InterfaceIDs = $InterfaceIDs | select -Unique
Once the unique list of InterfaceIDs is captured this will be used to find the correct TIBCO ActiveMatrix BusinessWorks services and to perform the needed operations in it.
Note : In the example setup it is sufficient to only modify the TIBCO ActiveMatrix BusinessWorks service, the TIBCO ActiveMatrix Adapter for SAP service will automatically follow as this is managed with TIBCO HAWK rules.
Second part of the script performs the operations on the TIBCO ActiveMatrix BusinessWorks services, this is different in the 2 scripts:
- SAP_BW_Manual_Stop.ps1
# For each interface find the corresponding TIBCO BW Service
Foreach ($InterfaceID in $InterfaceIDs) {
$Service = Get-WmiObject win32_service | Select Name, DisplayName |
Where-Object {$_.displayName.StartsWith("TIBCO ActiveMatrix BusinessWorks") -and $_.displayName.Contains($InterfaceID)} |
Sort DisplayName, Name
$Service | ForEach-Object –Process {
Set-Service $_.Name -StartupType Manual
Stop-Service $_.Name
}
}
- SAP_BW_Automatic_Start.ps1
# For each interface find the corresponding TIBCO BW Service
Foreach ($InterfaceID in $InterfaceIDs) {
$Service = Get-WmiObject win32_service | Select Name, DisplayName | Where-Object {$_.displayName.StartsWith("TIBCO ActiveMatrix BusinessWorks") -and $_.displayName.Contains($InterfaceID)} | Sort DisplayName, Name
$Service | ForEach-Object –Process {
Set-Service $_.Name -StartupType Automatic
Start-Service $_.Name
}
}
To run these PowerShell scripts you can create a bat file (.bat) with the below command.
powershell.exe -noexit -ExecutionPolicy Bypass -File "C:\PathToYourScript\SAP_BW_Manual_Stop.ps1"
powershell.exe -noexit -ExecutionPolicy Bypass -File "C:\PathToYourScript\SAP_BW_Automatic_Start.ps1"