Worklet: Install Adobe Reader for Windows

  • 18 October 2019
  • 0 replies
  • 297 views

Userlevel 7

This worklet checks for Adobe Reader and installs it if not found.



Evaluation code:



#REQUIRES -Version 2.0

<#

.SYNOPSIS

This Test script checks to see if Acrobat Reader is installed

.DESCRIPTION

This script queries the installed files for 32 and 64bit software

and returns a 0 if product is installed or 1 if not.

.Notes

File Name :Acrobat Reader_Install_Test.ps1

Author :Automox

Prerequisite :PowerShell V2 over win7 and upper

#>

#Handle Exit Codes:

trap { $host.ui.WriteErrorLine($_.Exception); exit 90 }



function Adobe_Reader_Install_Test {

# Application Name which is to be installation verified.

$appName = 'Adobe Acrobat Reader'

# Finding the Systen Directory (system32 Directory).

$sysDir = [Environment]::SystemDirectory



# Making the 32 bit and 64 bit path names blank.

$32BIT = ""

$64BIT = ""



#Get 32 bit software

Try {$32BIT=Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction Stop | Select-Object DisplayName | select-string "$appName" | out-string}

Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception; exit 90

}

# Script blcok to execute with powershell

# Match name in the block should be hard coded.

$scriptBlock = {$key = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object { $_.DisplayName -match 'Adobe Acrobat Reader'}; return $key }

# Get 64 bit registry

if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")

{

# if the host is in 64 bit systen.

Try

{

$64BIT = Get-ItemProperty 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction Stop | Select-Object DisplayName | select-string "$appName" | out-string

}

Catch

{

$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception; exit 90

}

# call for accessing the 64 bit registry incase 32 bit process not access the registry.

if ($64BIT -eq $null -Or $64BIT.Trim() -eq "")

{

Try

{

$installed64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)

$64BIT = $installed64.DisplayName

}

Catch

{

$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception; exit 90

}

}

} elseif ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "32-bit") {

# checking for the 64 bit registry on 32 bit host.

# in Script block line 38 match name should be hard coded and it should be proper.

Try {

$installed64 = @(& "$sysDir\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)

$64BIT = $installed64.DisplayName

}

Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;

Write-Output $Exception; exit 90

}

}



# Check for the Availability of the software and exit with relevent exit code.

if ($32BIT.Trim() -match $appName -Or ($64BIT -ne $null -And $64BIT.Trim() -match $appName)) {

#Application Found, Automox can handle the updates!

exit 0

} else {

# Application is not installed! Run Remediation Script to install it.

exit 1

}

}



Adobe_Reader_Install_Test



Remediation code:



#REQUIRES -Version 2.0

<#

.SYNOPSIS

This remediation script script will install Adobe Acrobat Reader DC

and immediatly update it to the newest version.

.DESCRIPTION

This script has the option for the user to specify the version which they want to install at "$latestVersion"

if the user not specified any version number to install,script downloads the installer into a powershell script

directry, executes it silently, and cleans up. it takes the latest version number by the directory listing,

for version of Reader with an .msi/.exe installer instead of .msp This is an example script that has been

tested to work on Win10 and Win7. This script may not work on all systems. Modify to fit your needs

.NOTES

File Name :Adobe_Reader_Install.ps1

Author :Automox

Prerequisite :PowerShell V2 over win7 and upper

#>

#Handle Exit Codes:

trap { $host.ui.WriteErrorLine($_.Exception); exit 90 }

# User can provide the version number which they want to install.

# if user not specified anything, script will check for the latest version from the ftp

# then install the latest version.

$latestVersion = ''

function Adobe_Reader_Install

{

#############User may update the settings in this block#######################

# Last Major Version:

# $mainURL="ftp://ftp.adobe.com/pub/adobe/reader/win/AcrobatDC/"

#####################################################################

# Check user input for the version number

# This block checks the latest version number from the ftp folder list.

Try

{

if ($latestVersion -eq "")

{

$ftpFolderUrl = "ftp://ftp.adobe.com/pub/adobe/reader/win/AcrobatDC/"

$ftpRequest = [System.Net.FtpWebRequest]::Create("$ftpFolderUrl")

$ftpRequest.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory

$ftpResponse = $ftpRequest.GetResponse()

$responseStream = $ftpResponse.GetResponseStream()

$ftpReader = New-Object System.IO.Streamreader -ArgumentList $responseStream

$dirList = $ftpReader.ReadToEnd()

$versionString = $dirList -split '[\r\n]' | Where { $_ } | Select -Last 1 -Skip 1

}

else

{

$versionString = $latestVersion.Replace(".", "")

}

}

Catch { Write-Output "Error in accessing the ftp folder" }



# Creating the ftp url for downloading the acreobat reader which we can get it from the wiki url

$installerurl = $ftpFolderUrl + $versionString + "/AcroRdrDC" + $versionString + "_en_US.exe"

# local path to save the exe file.

$output = "$PSScriptRoot\Acrobat_Reader_" + $versionString + ".exe"

# Creating WebClient Object.

$downloader = New-Object -TypeName System.Net.WebClient

# Download executable to the local drive.

Write-Output "Adobe Reader Installer is downloading..."

try

{

$downloader.DownloadFile($installerurl, $output);

Write-Output "Adobe Reader Installer download finished"

}

catch { Write-Output "File download failed. Check URL [$installerurl] and try again."; exit 90 }



#Start the installer, capture and return exit code

Write-Output "Installing Reader..."

try

{

$process = Start-Process -FilePath "$output" -ArgumentList "/qn EULA_ACCEPT=YES AgreeToLicense=Yes RebootYesNo=No /sAll" -Wait -PassThru -ErrorAction Stop;

Write-Output "Adobe Reader Install Finished."

}

Catch

{

$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber; Write-Output $Exception; exit 90

}

# Remove the installer downloaded.

Try { Remove-Item -force "$output" }

Catch { Write-Output "Skype Installer Not Available...`n"}

exit $process.ExitCode

}



Adobe_Reader_Install


0 replies

Be the first to reply!

Reply