Automated App Packaging – Firefox ESR

One of the biggest time drains for managing SCCM can be managing third party patching for SCCM. Not only do you have to try and keep track of new releases but then you have to go through packaging and testing. There are plenty of ways to do it, this is just one example of a powershell script that you can set to run on a schedule to help keep you up to date.

This script will go out to Firefox’s page, download the latest 64-bit ESR English(us) installer, check the version, compare it to the existing versions in the package source, create an application if it is a new version, distribute the content to your Distribution Points, create a test deployment and email you to let you know there is a new version available for testing.

This is similar to the script I posted for the FileZilla client although this has a different detection method and I have added in the automatic deployment to a test collection. Feel free to change and adapt this for your needs.

Automated App Packaging – FileZilla Client

You may also want to note that DetectDeploymentTypeByCustomScript and Add-CMDeploymentType have been deprecated but they still work as of CB v1902.

# Create Configuration Manager Application & Deployment Type for Firefox ESR 64-bit

#Email Addresses for notifications of new version
$email = "YourEmail@address.com"
$SCCMemail = "SCCMServer@mydomain.com"
$smtpServer = "smtp.mydomain.com"

#Distribution point group to distribute content to
$DPGroup = "All Distribution Points"

#Test User collection to deploy to
$TestCollection = "Test Users"

#AppPath
$AppPath = "\\srv-sccm2\CM_Sources$\Installs\Firefox"

#Get Download and Version info
#Parse Landing Page
$HTML = Invoke-WebRequest -UseBasicParsing -URI "https://www.mozilla.org/en-US/firefox/organizations/all/"
#Regex out version
$versioncapture = $HTML.Content | Select-String -Pattern '(?:data-esr-versions=")(?<version>[0-9]+\.[0-9]+\.[0-9]+)'
#select version form capture groups
$version = $versioncapture.Matches[0].Groups["version"].Value
#select url from links content
$url = $HTML.Links | Where-Object {$_.'data-download-language' -eq "english (us)" -and $_.title -eq "Download for Windows 64-bit in English (US)"} | select -ExpandProperty HREF

#Download File
If(($version | Measure-Object -Character | select Characters -ExpandProperty Characters) -eq "6"){  # Check version String
$filename = "Firefox Setup $version" + "esr.exe"
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($url,"$AppPath\$filename")
}
ELSE
{
Exit
}

# New Version?
$folders = Get-ChildItem $AppPath | select -ExpandProperty Name
If($folders -like $version + "esr"){$NewVer = $false}else{$NewVer = $true}

If($NewVer -eq $false){exit}
else{
    
    #Get Install FIle
    $InstallFile = Get-Item -Path $AppPath\$filename
    $Installer = $InstallFile.Name
    $FinalInstaller = "`"$installer`""

    # Create Folder and Copy Template w/ MSI
    $NewFolder = New-Item -Path $AppPath\$($version + "esr") -ItemType Directory
    Copy-Item -Path $AppPath\$FileName -Destination $NewFolder -Force

    # Set Application Name
    $ApplicationName = ($InstallFile.BaseName).replace("Setup ","")

    # Detect Script
    $DetectScript = [scriptblock]::Create("If(Test-Path 'C:\Program Files\Mozilla Firefox\firefox.exe'){If((Get-Item 'C:\Program Files\Mozilla Firefox\firefox.exe').VersionInfo.ProductVersion -ge '$version'){return `"$True`"}}")

    # Import CM Module
    Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
    
    # Get CM Site Information
    $siteserver = Get-PSDrive -PSProvider CMSite | select -ExpandProperty Root
    $sitecode = Get-PSDrive -PSProvider CMSite | select -ExpandProperty Name

    # Set Vars
    $Namespace = "root/sms/site_$SiteCode"
    $IconFile = "$AppPath\Firefox.png"
    $ContentLocation = $NewFolder.FullName
    $InstallProg = "$FinalInstaller -ms"
    $UninstallProg = '"C:\Program Files\Mozilla Firefox\uninstall\helper.exe" /S'
    $Publisher = 'Mozilla'

    # Change Location to PSDrive
    Set-Location $sitecode":"

    # Create CM Application
    New-CMApplication -Name "$ApplicationName" -Publisher "$Publisher" -SoftwareVersion "$ProductVersion" -LocalizedApplicationName "$ApplicationName" -LocalizedApplicationDescription "$CatalogDescription" -IconLocationFile "$IconFile" -AutoInstall $True
    
    # Create CM Deployment Type
    Add-CMDeploymentType -ApplicationName $ApplicationName -ScriptInstaller -DeploymentTypeName $ApplicationName -InstallationFileLocation "$ContentLocation" -InstallationProgram $InstallProg -UninstallProgram $UninstallProg -DetectDeploymentTypeByCustomScript -ScriptType PowerShell -ScriptContent $DetectScript -InstallationBehaviorType InstallForSystem -LogonRequirementType WhetherOrNotUserLoggedOn -InstallationProgramVisibility Hidden -MaximumAllowedRunTimeMins '30' -EstimatedInstallationTimeMins '15'
            
    # Move Application to Desired Folder
    $Application = Get-CMApplication -Name $ApplicationName
    Move-CMObject -FolderPath $SiteCode":\Application\Firefox" -InputObject $Application

    # Distribute Content
    Start-CMContentDistribution -ApplicationName $ApplicationName -DistributionPointGroupName "$DPGroup"
    
    #Create Test Deployment
    New-CMApplicationDeployment -CollectionName "$TestCollection" -Name "$ApplicationName" -DeployAction Install -DeployPurpose available -UserNotification DisplaySoftwareCenterOnly -AvailableDateTime "Tuesday, June 11, 2019 8:00:00 AM" -TimeBaseOn LocalTime

    # Send Email Notification
    Send-MailMessage -SmtpServer $smtpServer -From $SCCMemail -To $email -Subject "New SCCM Application Created for $ApplicationName" -Body "$ApplicationName script has finished processing. It is ready for testing."

    }

Leave a Reply

Your email address will not be published. Required fields are marked *