Overblog
Editer l'article Suivre ce blog Administration + Créer mon blog
Windows - Virtualization - PowerShell - Active Directory - Office

[Control-M] Deploy agent v8 and patch with PowerShell silently

16 Juillet 2019 , Rédigé par Aurel Publié dans #PowerShell, #Windows

This PowerShell script (compatible PowerShell v2) install Control-M agent version 8.0.00 and patch it to 8.0.00.200 silently. It also open Windows firewall ports in 7825 / out 7826

Regarding the patch (PAKAI) source, you need to extract the .exe (with 7 Zip for example)

You also need to create xml file with parameters in it like below, in this script there are 3 xml files (for different environments) and you need to call the script following by the environment : CTLM-agent-v8-SCCM-install.ps1 -Env DEV

 

<AutomatedInstallation langpack="eng">
    <target.product>Control-M/Agent 8.0.00</target.product>
    <agent.parameters>
        <entry key="ctm_agent.Domain" value=""/>
        <entry key="ctm_agent.Tracker.Event.Port" value="7035"/>
        <entry key="field.Agent.To.Server.Port.Number" value="7826"/>
        <entry key="ctm_agent.Tcp_ip.Timeout" value="60"/>
        <entry key="INSTALL_PATH" value="C:\Program Files\BMC Software"/>
        <entry key="ctm_agent.Service.User.Name" value=""/>
        <entry key="field.Authorized.Controlm.Server.Host" value="serverXX|serverYY"/>
        <entry key="ctm_agent.Logon.As.User" value="N"/>
        <entry key="field.Server.To.Agent.Port.Number" value="7825"/>
        <entry key="ctm_agent.Default.Printer" value=""/>
        <entry key="ctm_agent.JO.Statistic" value=""/>
        <entry key="ctm_agent.Service.User.Password" value="!!!toto="/>
        <entry key="field.Primary.Controlm.Server.Host" value="serverXX"/>
    </agent.parameters>
</AutomatedInstallation>

 

PowerShell script  :

 

# ***********************************************************************************************
# Script Name......: CTLM-agent-v8-install.ps1
# Function.........: Deploy Control-M agent version 8.0.00.200 on a Windows server
# Version / Author.: ABA / 1.0 (2019/02/11)
#
# CHANGES :
#
# ***********************************************************************************************

<#
.SYNOPSIS
    .
.DESCRIPTION
    Deploy Control-M agent version 8.0.00.200 on a Windows server
    This script is compatible with PowerShell version 2
.PARAMETER action
    Specfies the environments with -Env. Valid values are PROD | VAL | DEV
.EXAMPLE
    C:\PS>.\CTLM-agent-v8-install.ps1 -Env DEV
.NOTES
    Author: ABA
    Date:   2019/02/11
#>

param(
    [Parameter( Mandatory=$false)]
    [string]$Env    
)

# variables
$BinPath = "C:\Temp\CTLM"
$TranscriptLogFile = "C:\Temp\CTLM\CTLM_agent_install_transcript.log"
$versionAgent = "8.0.00.200"

 

new-Item -ItemType directory -Path $BinPath

Start-Transcript -Path $TranscriptLogFile -force

Write-Host "$(Get-Date -Format g) Install... Starting" -Foreground Yellow

# region Install DRKAI 8.0.00_windows_x86_64 & PAKAI.8.0.00.200_windows_x86_6

Write-Host "$(Get-Date -Format g) Starting Install CTLM Agent ..." -foreground green -noNewline

# Conf File Env Path
$ProdPath = ".\controlm_prod.xml"
$DevPath = ".\controlm_dev.xml"
$ValPath = ".\controlm_val.xml"
$InstallPath = $null

# Check ENV
    If ($Env) {
    
        switch ($Env) {

        'PROD'   {write-host "CTLM Agent Installation on PROD Servers" -foreGroundColor yellow ; $InstallPath = $ProdPath;}
        'DEV'    {write-host "CTLM Agent Installation on DEV Servers" -foreGroundColor yellow ; $InstallPath = $DevPath;}
        'VAL'    {write-host "CTLM Agent Installation on VAL Servers" -foreGroundColor yellow ; $InstallPath = $ValPath;}
        }
    }

    # check if installed
    If (get-service ctmag -ErrorAction SilentlyContinue){
        write-host "$(Get-Date -Format g) CTLM Agent already Installed" -foreground yellow
    }
    
    Elseif ($installPath -ne $null) {
        write-host "$(Get-Date -Format g) Installing DRKAI 8.0.00_windows_x86_64 ....Please wait" -foregroundColor yellow
        
        start-process -filepath ".\DRKAI.8.0.00_windows_x86_64\setup.exe" -ArgumentList "-silent $InstallPath" -wait
        
        write-host "$(Get-Date -Format g) Install DRKAI 8.0.00_windows_x86_64 Completed" -ForeGroundColor green
        
        # Patch PAKAI.8.0.00.200_windows_x86_6
        
        # Stopping service ctmag
        Write-Host "$(Get-Date -Format g) Stopping service CTMAG..." -foreground green -noNewline
        
        Start-Sleep -Seconds 5

        Set-Service -inputobject ctmag -status Stopped -ErrorAction SilentlyContinue -ErrorVariable ProcessError;
        
        If ($ProcessError) {
            Write-Host "Service cmtag not found ... check if CTLM agent is well installed - log in C:\Users\x\AppData\Local\Temp\x\BMC_xx" -foreground green -noNewline
        }
        
        Start-Sleep -Seconds 3
        
        Write-Host "Service CTMAG...Stopped" -foreground Yellow
        
        Write-Host "$(Get-Date -Format g) Installing PAKAI.8.0.00.200_windows_x86_64 ..." -foreground green -noNewline
        
        & ".\PAKAI.8.0.00.200_windows_x86_64\PAKAI.8.0.00.200_windows_x86_64\silent.bat"

        
        
        Start-Sleep -Seconds 2
        
        # Get FIX_NUMBER (PAKAI.8.0.00.200)        
        $FIX_NUMBER = (Get-ItemProperty -Path Registry::'HKEY_LOCAL_MACHINE\SOFTWARE\BMC Software\Control-M/Agent\CONFIG' -Name FIX_NUMBER).FIX_NUMBER

        #  if FIX_NUMBER (PAKAI.8.0.00.200) ie install patch OK
        if ($FIX_NUMBER -eq "PAKAI.8.0.00.200") {
                        
            write-host "Install PAKAI.8.0.00.200_windows_x86_64 Completed" -ForeGroundColor Yellow            
        }
        
       else {
                        
            write-host "Install PAKAI.8.0.00.200_windows_x86_64 Failed !" -ForeGroundColor Yellow            
                
        }
            
    }
    
    Else {
        write-host "$(Get-Date -Format g) No Env specified, Please use the script correctly" -foreground red
    }
    
    write-host "$(Get-Date -Format g) Install CTLM Agent Completed" -ForeGroundColor Yellow

#endregion

# region Add Firewall Rules port in 7825 / out 7826

Write-Host "$(Get-Date -Format g) Add Firewall Rules port in 7825 / out 7826 ..." -foreground green

netsh advfirewall firewall add rule name="Control-M Agent" dir=in protocol=tcp localport=7825 remoteip=any action=allow
netsh advfirewall firewall add rule name="Control-M Agent" dir=out protocol=tcp localport=7826 remoteip=any action=allow

write-host "$(Get-Date -Format g) Firewall Rules added" -ForeGroundColor Yellow
        
#endregion

write-host "$(Get-Date -Format g) Install...Completed" -ForeGroundColor Yellow

Stop-Transcript

 

Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article