We use cookies on our website to ensure we provide you with the best experience on our website. By using our website, you agree to the use of cookies for analytics and personalized content.This website uses cookies. More Information
It seems like your browser didn't download the required fonts. Please revise your security settings and try again.
Barracuda Content Shield

Example Powershell Script for GPO Deployment of BCS Suite for Windows

  • Last updated on

This sample Powershell script is ONLY an example, which you can follow as a template for your GPO deployment of the Barracuda Content Shield Suite for Windows. This script is not guaranteed by Barracuda, and you must replace the parameter values with your own.

param(
    [string]$action='',
    [string]$workDir='',
    [string]$setupName='',
    [string]$keyName='',
    [string]$version='',
    [string]$userPass=''
) #Must be the first statement in the script
#### CUSTOM SETUP ######################################################
<# 
=NOTES =================================================================
 
 -- TESTED WITH WINDOWS 10 only. Needs adjustments for running on WIN7 (PS < 3.0), 
                       i.e. "Tee-Object" --
 *** Adjust the parameters for install/upgrade or uninstall based on your own setup!
 
 Deploy via GPO: 
  Create a per-machine GPO that executes a startup script 
  (make sure it runs elevated) that invokes the Powershell script - or 
  any other script that you created to install / remove the 
  agent suite installer (executable).
 Return codes:
  3010 - Uninstall successful. Reboot pending: On uninstall a 
         reboot is required before reinstalling the agent.
  0    - Installation successful. (Also on a "remove" action, if 
         the agent is not installed).
  1603 - Uninstall canceled. Most likely because either the Tamper Proof 
         feature is disabled, or the wrong password was provided.
  1602 - Install aborted. Check KEYPATH value.
  For any of the 16xx return codes, please check the component 
  MSI logs, which can be found in the %temp% folder of the process owner.
========================================================================
#>
New-Item -Path C:\gpo\ -ItemType File -Name mylog.log
Add-Content -Path C:\gpo\mylog.log -Value "$(Get-Date) - $workDir\ConfigureBcsPlus.ps1 has run as an Immediate Scheduled Task"
# ACTION: set the action to do in this script:( install | remove )
$ACTION=$action
# BASE_DIR: set your network share folder as base dir and some other values
$BASE_DIR       =$workDir
# SETUP_FILENAME: by default named BarracudaContentShieldSetup-[VERSION].exe. 
# If you rename this field, make sure to also fill in the VERSION field below.
$SETUP_FILENAME =$setupName
# KEY_FILENAME: by default named bcs.key. Change this property if you 
# plan to rename this key (but make sure to keep ".key" as the extension)
$KEY_FILENAME   =$keyName
#VERSION: no need to set this if you plan to keep the filename original 
# (which contains the version). 
# In that case, the following lines extract the version from the file name
$VERSION        =$version   
#### SETUP DONE ########################################################
if($VERSION -eq ""){
    #Try to get it from our setup name. 
    #This can only work if the name is not modified
    $VERSION        =($SETUP_FILENAME).split("-""")[1]
    $VERSION = $VERSION.Substring(0,$VERSION.Length-4)
    # TODO: some regex to validate the result is in fact a version number
}
$ErrorActionPreference="Stop"
$level=@{INFO="[INFO]";WARNING="[WARN]";ERROR="[ERROR]"} 
$date=(Get-Date).ToString('MMddyy_HHmmss')
$MMddyyyy=(Get-Date).ToString('MM-dd-yyyy');
# creates an operational log file in that same dir
$LOG_FILE=$BASE_DIR + "\install.log"
# Starting script execution
Write-Output "*** START *** $(Get-Date) **********************************************" | Tee-Object -FilePath $LOG_FILE -Append #| Out-File $LOG_FILE -Append -Force;
Write-Output "$(Get-Date) : $($level["INFO"]) Starting the script " | Tee-Object -FilePath $LOG_FILE -Append
Write-Output "$(Get-Date) : $($level["INFO"]) Params: ACTION=$action, WORKDIR=$workDir, SETUP_NAME=$setupName, KEY_NAME=$keyName, VERSION=$version" | Tee-Object -FilePath $LOG_FILE -Append
Set-Location -Path "$BASE_DIR" -PassThru
$bcs_suite_installed=''
$bcs_cpa_installed=''
$bcs_wca_installed=''
function ExitWithCode
{
    param
    (
        [Int32]$exitcode
    )
    
    if($exitcode-eq 3010){
        # we expect exitcode 3010, as this just states pending reboot.
        # you can check the component logs in %temp% folder (MSI*.log) 
        # for further details on the installation of each component.
        Write-Host "Requested action '$ACTION' finished with return code: $exitcode. The actions was successful. A Reboot is pending."
        exit 0   #handle as success
    }
    else{
        Write-Host "Action '$ACTION' finished with return code: $exitcode"
    }
    
    $host.SetShouldExit($exitcode)
    
    exit $exitcode
    
}
function InstallOrUpgradeBCSPlus 
{
    # Install Barracuda Content Shield Suite from shared network folder
    $process = (Start-Process -FilePath "$BASE_DIR\$SETUP_FILENAME" -ArgumentList "KEYPATH=$BASE_DIR\$KEY_FILENAME","/silent" -PassThru -Wait)
    ExitWithCode -exitcode $process.ExitCode
}
function UninstallBCSPlus {
    # Uninstall Barracuda Content Shield Suite from system
    $process = (Start-Process -FilePath "$BASE_DIR\$SETUP_FILENAME" -ArgumentList "USER_PASS=$userPass","/silent","/remove" -PassThru -Wait)
    ExitWithCode -exitcode $process.ExitCode
}
function CheckInstallationBCSPlus
{
    # ---- Check registry if BCS is installed ---- 
    $UninstallKeys = 
    "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall", 
    "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    $guid = @{ 
        "CPA" = "`{0F536D44-C0A5-4DCC-BAC9-5724FFB91D64`}"; 
        "WCA" = "`{CEB35DBB-E633-452D-A876-0CA0DC9D4DC0`}"; 
        "Suite" = "`{3877F3A3-358E-49C2-BFA7-9A63994D2FCA`}"
    }
    $suite_ver=''
    $cpa_ver=''
    $wca_ver=''
    foreach($key in $UninstallKeys)
    {
        if(Test-Path "$key\$($guid.Suite)" -ErrorAction SilentlyContinue){
            
            #find out the version installed
            $display_version = Get-ItemProperty -Path "$key\$($guid.Suite)" -Name DisplayVersion 
            $suite_ver="$($display_version.DisplayVersion)"
        }
        if(Test-Path "$key\$($guid.CPA)" -ErrorAction SilentlyContinue){
        
            #find out the version installed
            $display_version = Get-ItemProperty -Path "$key\$($guid.CPA)" -Name DisplayVersion
            $cpa_ver="$($display_version.DisplayVersion)"
        }
        if(Test-Path "$key\$($guid.WCA)" -ErrorAction SilentlyContinue){
             
            $display_version = Get-ItemProperty -Path "$key\$($guid.WCA)" -Name DisplayVersion
            $wca_ver="$($display_version.DisplayVersion)"
        }
    }
    Return $suite_ver, $cpa_ver, $wca_ver
}
# get versions installed
$bcs_suite_installed ,$bcs_cpa_installed, $bcs_wca_installed = CheckInstallationBCSPlus
Write-Output "$(get-date) : $($level["INFO"]) SUITE: $bcs_suite_installed, CPA: $bcs_cpa_installed, WCA: $bcs_wca_installed" | Tee-Object -FilePath $LOG_FILE -Append
if ($ACTION -eq "install")
{
    if($bcs_suite_installed -eq '')
    {
        Write-Output "$(get-date) : $($level["INFO"])  INSTALL BCS v$VERSION" | Tee-Object -FilePath $LOG_FILE -Append
        InstallOrUpgradeBCSPlus
    }
    else
    {    
        if($VERSION -gt $bcs_suite_installed)
        {
            Write-Output "$(get-date) : $($level["INFO"])  UPGRADE ($VERSION > $bcs_suite_installed)" | Tee-Object -FilePath $LOG_FILE -Append
            InstallOrUpgradeBCSPlus
        }
        elseif($VERSION -lt $bcs_suite_installed)
        {
            Write-Output "$(get-date) : $($level["INFO"])  NO ACTION (up to date: $VERSION < $bcs_suite_installed)" | Tee-Object -FilePath $LOG_FILE -Append
        }
        elseif($VERSION -eq $bcs_suite_installed)
        {
            # NOTE: 
            # If you run 'install' on the same version installed, 
            # it will try to uninstall the installed version. 
            # If that is your intention, for that you need to pass 
            # the password parameter.
            Write-Output "$(get-date) : $($level["INFO"])  NO ACTION (same: $VERSION == $bcs_suite_installed)" | Tee-Object -FilePath $LOG_FILE -Append
        }
    }
}
elseif ($ACTION -eq "remove")
{
    if ($bcs_suite_installed -ne '')
    {
        Write-Output "$(get-date) : $($level["INFO"])  UNINSTALL BCS..." | Tee-Object -FilePath $LOG_FILE -Append
        UninstallBCSPlus
    }
    else{
        Write-Output "$(get-date) : $($level["INFO"])  NO ACTION (No BCS installed. No action necessary.)" | Tee-Object -FilePath $LOG_FILE -Append
    }
}
else
{
    Write-Output "$(get-date) : $($level["ERROR"])  UNKNOWN ACTION: $ACTION (Pick install | remove)" | Tee-Object -FilePath $LOG_FILE -Append
}
Write-Output "*** DONE *** $(Get-Date) *********************************************" | Tee-Object -FilePath $LOG_FILE -Append
ExitWithCode -exitcode 0
Last updated on