Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
714 views

script to add workgroup server

Any powershell scripts to add workgroup server in the Enterprise studio.?

 

thanks,

Sarath.

0 Likes
3 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Yes! Enterprise Studio automation is the last bit missing in having a fully automated CM deployment with Docker etc...

There may be something in the TRIMconfig.tcfg XML file, I haven't looked too much into that

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

# HPRM8 script to run in case of a DR event
# Sets the IDOL service to DR server
# Sets event servers to DR server
# Sets the workgroup server used for redirected queries to DR server
# Server names will match naming convention of datacentre where the script is run

# 18 October 2016

# QA values
$DatasetID = '45' 
$configFile = 'D:\HPRM83\ServerData\TRIM\TRIMconfig.tcfg'
$drEventServer = 'PTrimWGServer01' # and IDOL server
$drWorkgroupServer = 'PTrimWGServer02'
$branchServers = @()
#>

# Set the server names to match the datacentre where script is run
if ($env:COMPUTERNAME -match "^(\w{1,1})") {
    $dataCentreId = $Matches[1]
    $drEventServer = $drEventServer -replace "^(\w{1,1})",$dataCentreId
    $drWorkgroupServer = $drWorkgroupServer -replace "^(\w{1,1})",$dataCentreId
}

# The HP.HPTRIM.SDK.TrimEnterpriseConfiguration.SaveAndDeploy() function will 
# only work with Powershell 2.0
if (($Host | select -ExpandProperty version) -ne '2.0') { 
    Write-Host "Exiting!" -ForegroundColor Red
    Write-Host "This script needs to be run with Powershell v2.0 e.g." -ForegroundColor Red
    Write-Host "powershell.exe -version 2.0 -file $($MyInvocation.InvocationName)" -ForegroundColor Blue -BackgroundColor White
    return
}

# Load the .NET version of the SDK (for 8.x on)
[reflection.assembly]::LoadWithPartialName("HP.HPTRIM.SDK") | Out-Null
[HP.HPTRIM.SDK.TrimApplication]::Initialize()

# Backup existing config file
Copy-Item $configFile -Destination ($configFile -replace ".tcfg",".tcfg.$(get-date -Format "yyyyMMddHHmmss").bak")

# Load config XML
[xml]$trimConfig = gc $configFile

# Get the node for the production dataset to update
$datasetNode = $trimConfig.TRIMConfigRootName.DataSources.Dataset | ? { $_.dbid -eq $DatasetID }

# Update IDOL server
$datasetNode.ContentIndexParams.DCIServer = $drEventServer

# Get IDs of DR workgroup and event servers
$drEventServerID = $trimConfig.TRIMConfigRootName.WorkgroupServers.WGS | ? { $_.name -eq $drEventServer } | select -ExpandProperty workgroupID
$drWorkgroupServerID = $trimConfig.TRIMConfigRootName.WorkgroupServers.WGS | ? { $_.name -eq $drWorkgroupServer } | select -ExpandProperty workgroupID

# Update event service configuration
foreach ($n in $datasetNode.EventProcessors.SelectNodes('./*/OnlyOnWGS')) {
    if ($n.InnerText -ne '') {
        $n.InnerText = $drEventServerID
    }
}

# Update workgroup servers that redirect database requests
foreach ($bs in $branchServers) {
    $wgNode = $trimConfig.TRIMConfigRootName.WorkgroupServers.WGS | ? { $_.name -eq $bs }
    $wgNode.RemoteWorkgroupId = $drWorkgroupServerID.ToString()
}

# Write out updated config file 
$trimConfig.InnerXml -replace "\n","`r`n" | Out-File $configFile -Encoding ascii -Force

# Save and deploy changes (this updates the GMTdateTimeModified value)
try {
    $enterpriseConfig = New-Object HP.HPTRIM.SDK.TrimEnterpriseConfiguration
    $enterpriseConfig.Save()
    $enterpriseConfig.SaveAndDeploy()
    Write-Host "TRIM config has been updated to use $drEventServer and $drWorkgroupServer servers." -ForegroundColor Cyan
} catch {
    Write-Host "Error deploying changes. Error message is: `n$($_.Exception.Message)" -ForegroundColor Red
    Write-Host "As a workaround, open the Enterprise Studio and deploy from there." -ForegroundColor DarkMagenta -BackgroundColor White
}

Write-Host "`nScript finished."

If it helps, here's a PowerShell script I've used to update the active IDOL server and events servers if we need to switch over to another data centre for a DR test etc. As @JanMartin suggested, it's just updating the TRIMconfig.tcfg XML file and then doing a save and deploy. Not sure how this would work with adding a workgroup server from scratch, but if it's just a matter of adding a new workgroup server node to the XML with the correct values (e.g. increment the server ID number) and then doing a save and deploy, then it might be possible to script it.

This is for 8.3 only. Haven't tested this in later versions just yet. No warranties! 🙂

Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Hi  davros29,

thanks for your script. i had modified to match my requirement. i have CM9.2 at our side and there is no SaveAndDeploy() method in the TrimEnterpriseConfiguration class. this line throwing error message.

thanks,

Sarath.

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.