Package and Deploy Chrome using PowerShell

This post tells you how to download, package, and deploy Google Chrome using Powershell

This code was provided from this source:

$URI = ''
$OutFile = 'E:\temp\GoogleChromeStandaloneEnterprise64.msi'
$Proxy = 'http://lookatmeimaproxy:80'
$SCCMSource = '\\server\share\Google\Chrome'
$SCCMSiteCode = 'ABC'

# Download Chrome from the web
Write-Output "Downloading $URI to $OutFile"
$start_time = Get-Date
Invoke-WebRequest -Uri $URI -OutFile $OutFile -Proxy $Proxy
Write-Output "Download completed in: $((Get-Date).Subtract($start_time).Seconds) second(s)"

# Get file metadata
$a = 0 
$objShell = New-Object -ComObject Shell.Application 
$objFolder = $objShell.namespace((Get-Item $OutFile).DirectoryName) 

foreach ($File in $objFolder.items()) {
    IF ($file.path -eq $outfile) {
        $FileMetaData = New-Object PSOBJECT 
        for ($a ; $a  -le 266; $a++) {  
         if($objFolder.getDetailsOf($File, $a)) { 
             $hash += @{$($objFolder.getDetailsOf($objFolder.items, $a)) = $($objFolder.getDetailsOf($File, $a)) }
            $FileMetaData | Add-Member $hash 
           } #end if 
       } #end for  

# Move the downloaded file to the appropriate location
$ChromeVersion = $FileMetaData.Comments.split(' ')[0]
Write-Output "Downloaded version: $ChromeVersion"
$Filename = $((get-item $OutFile).name)
$destinationfolder = "$SCCMSource\$chromeversion"
Write-Output "Destination folder is $destinationfolder"

IF (!(test-path $destinationfolder)) {
    Write-Output "$destinationfolder does not exist"
    Write-Output "Creating $destinationfolder"
    Write-Output "Moving $OutFile to $destinationfolder"

    $SavedPath = $(pwd)
    IF (!(Get-WindowsFeature RSAT-AD-PowerShell).installed) {Add-WindowsFeature RSAT-AD-PowerShell}
    IF (!(Get-Module ConfigurationManager)) {Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)}
    IF ($(pwd).path -ne "$SCCMSiteCode`:\") {Set-Location "$SCCMSiteCode`:"}
    IF (!(Get-CMDeploymentType -ApplicationName "google chrome" -DeploymentTypeName "Google Chrome - $chromeversion")) {
        Write-Output "No deployment type exists for Google Chrome $ChromeVersion"
        Add-CMMsiDeploymentType -ApplicationName "Google Chrome" -ContentLocation "$destinationfolder\$filename" -Comment "Automatically added by powershell magic: $(get-date)" -DeploymentTypeName "Google Chrome - $ChromeVersion" -InstallationBehaviorType InstallForSystem -InstallCommand "msiexec /i GoogleChromeStandaloneEnterprise64.msi /qn" -MaximumRuntimeMins 15 -EstimatedRuntimeMins 5 | Select LocalizedDescription, LocalizedDisplayName
        WHILE ($((get-CMDeploymentType -ApplicationName 'Google Chrome' -DeploymentTypeName "Google Chrome - $chromeversion").PriorityInLatestApp) -ne '1') {
            Write-Output "Priority currently: $((get-CMDeploymentType -ApplicationName 'Google Chrome' -DeploymentTypeName "Google Chrome - $chromeversion").PriorityInLatestApp)"
            Write-Output "Increasing priority"
            Set-CMDeploymentType -ApplicationName "Google Chrome" -DeploymentTypeName "Google Chrome - $chromeversion" -Priority Increase
        Set-CMApplication -ApplicationName 'Google Chrome' -SoftwareVersion $chromeversion
    Set-Location $SavedPath
    Write-Output "$destinationfolder already exists"
    Remove-Item $OutFile
    Write-Output "Removed $OutFile"
Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment


Post a Comment