Jump to content

Recommended Posts

Posted
<#
===========================================================================
Script Name : Install-Smoothwall.ps1
Purpose     : Installs the Smoothwall Safeguarding Client via GPO Startup

Description :
    - Designed to run as a Computer Startup Script via Group Policy.
    - Automatically detects the single MSI file located in the same
      directory as this script.
    - Reads ORGID, SERIALID, and optional ENABLEAZUREAD values from
      sw-config.txt in the same directory.
    - Executes msiexec silently (/qn /norestart).
    - Generates:
          • Wrapper log  : C:\ProgramData\Logs\SW\
          • MSI verbose log (/L*v)
    - Returns the native MSI exit code to Windows.

Requirements :
    - This script, the MSI installer, and sw-config.txt must reside
      in the same folder (typically a UNC deployment share).
    - Only ONE .msi file must exist in the folder.
    - Computer account must have read access to the share.
    - Runs under SYSTEM context.

Exit Codes :
    0      = Success
    3010   = Success (reboot required)
    1603   = Fatal MSI error
    1      = Script validation failure (missing MSI/config/etc.)

===========================================================================
#>

$LogDir = "C:\ProgramData\Logs\SW"
$TimeStamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$LogFile = Join-Path $LogDir "Smoothwall-$TimeStamp.log"
$MsiLog  = Join-Path $LogDir "Smoothwall-MSI-$TimeStamp.log"

$ScriptDir  = $PSScriptRoot
$ConfigPath = Join-Path $ScriptDir "sw-config.txt"

# Ensure log directory exists
if (!(Test-Path $LogDir)) {
    New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
}

Add-Content -Path $LogFile -Value "===== $(Get-Date) : Installation Started ====="

# Detect MSI in script folder
$MsiFiles = Get-ChildItem -Path $ScriptDir -Filter *.msi -File

if ($MsiFiles.Count -eq 0) {
    Add-Content -Path $LogFile -Value "ERROR: No MSI file found in $ScriptDir"
    exit 1
}

if ($MsiFiles.Count -gt 1) {
    Add-Content -Path $LogFile -Value "ERROR: Multiple MSI files found in $ScriptDir"
    exit 1
}

$MsiPath = $MsiFiles[0].FullName
Add-Content -Path $LogFile -Value "MSI detected: $MsiPath"

# Validate config exists
if (!(Test-Path $ConfigPath)) {
    Add-Content -Path $LogFile -Value "ERROR: Config not found: $ConfigPath"
    exit 1
}

# Read config
$Params = @{}
Get-Content $ConfigPath | Where-Object { $_ -match "=" } | ForEach-Object {
    $Parts = $_ -split "=", 2
    if ($Parts.Count -eq 2) {
        $Params[$Parts[0].Trim()] = $Parts[1].Trim()
    }
}

# Validate required values
if (-not $Params["ORGID"] -or -not $Params["SERIALID"]) {
    Add-Content -Path $LogFile -Value "ERROR: ORGID or SERIALID missing in config."
    exit 1
}

if (-not $Params["ENABLEAZUREAD"]) {
    $Params["ENABLEAZUREAD"] = "#0"
}

# Build MSI arguments
$Arguments = @(
    "/i `"$MsiPath`""
    "ORGID=$($Params["ORGID"])"
    "SERIALID=$($Params["SERIALID"])"
    "ENABLEAZUREAD=$($Params["ENABLEAZUREAD"])"
    "/qn"
    "/norestart"
    "/L*v `"$MsiLog`""
) -join " "

# Run installer
$Process = Start-Process -FilePath "msiexec.exe" `
    -ArgumentList $Arguments `
    -Wait `
    -PassThru

$ExitCode = $Process.ExitCode

Add-Content -Path $LogFile -Value "Exit Code: $ExitCode"
Add-Content -Path $LogFile -Value "===== $(Get-Date) : Installation Finished ====="
Add-Content -Path $LogFile -Value ""

exit $ExitCode

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...