Created
July 11, 2014 19:10
-
-
Save rgsteele/f08f817d955440bb98c4 to your computer and use it in GitHub Desktop.
Lenovo Battery Recall 2014 PSAppDeployToolkit script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This script performs the installation or uninstallation of an application(s). | |
.DESCRIPTION | |
The script is provided as a template to perform an install or uninstall of an application(s). | |
The script either performs an "Install" deployment type or an "Uninstall" deployment type. | |
The install deployment type is broken down in to 3 main sections/phases: Pre-Install, Install, and Post-Install. | |
The script dot-sources the AppDeployToolkitMain.ps1 script which contains the logic and functions required to install or uninstall an application. | |
To access the help section, | |
.EXAMPLE | |
Deploy-Application.ps1 | |
.EXAMPLE | |
Deploy-Application.ps1 -DeploymentMode "Silent" | |
.EXAMPLE | |
Deploy-Application.ps1 -AllowRebootPassThru -AllowDefer | |
.EXAMPLE | |
Deploy-Application.ps1 -Uninstall | |
.PARAMETER DeploymentType | |
The type of deployment to perform. [Default is "Install"] | |
.PARAMETER DeployMode | |
Specifies whether the installation should be run in Interactive, Silent or NonInteractive mode. | |
Interactive = Default mode | |
Silent = No dialogs | |
NonInteractive = Very silent, i.e. no blocking apps. Noninteractive mode is automatically set if an SCCM task sequence or session 0 is detected. | |
.PARAMETER AllowRebootPassThru | |
Allows the 3010 return code (requires restart) to be passed back to the parent process (e.g. SCCM) if detected from an installation. | |
If 3010 is passed back to SCCM a reboot prompt will be triggered. | |
.PARAMETER TerminalServerMode | |
Changes to user install mode and back to user execute mode for installing/uninstalling applications on Remote Destkop Session Host/Citrix servers | |
.NOTES | |
.LINK | |
Http://psappdeploytoolkit.codeplex.com | |
"#> | |
Param ( | |
[ValidateSet("Install","Uninstall")] | |
[string] $DeploymentType = "Install", | |
[ValidateSet("Interactive","Silent","NonInteractive")] | |
[string] $DeployMode = "Interactive", | |
[switch] $AllowRebootPassThru = $false, | |
[switch] $TerminalServerMode = $false | |
) | |
#*=============================================== | |
#* VARIABLE DECLARATION | |
Try { | |
#*=============================================== | |
#*=============================================== | |
# Variables: Application | |
$appVendor = "Lenovo" | |
$appName = "Battery Program" | |
$appVersion = "2014" | |
$appArch = "" | |
$appLang = "EN" | |
$appRevision = "01" | |
$appScriptVersion = "1.0.0" | |
$appScriptDate = "07/08/2014" | |
$appScriptAuthor = "rgsteele" | |
#*=============================================== | |
# Variables: Script - Do not modify this section | |
$deployAppScriptFriendlyName = "Deploy Application" | |
$deployAppScriptVersion = [version]"3.1.3" | |
$deployAppScriptDate = "05/22/2014" | |
$deployAppScriptParameters = $psBoundParameters | |
# Variables: Environment | |
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition | |
# Dot source the App Deploy Toolkit Functions | |
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1" | |
#*=============================================== | |
#* END VARIABLE DECLARATION | |
#*=============================================== | |
#*=============================================== | |
#* PRE-INSTALLATION | |
If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation" | |
#*=============================================== | |
# Test whether the site is reachable | |
$HTTP_Request = [System.Net.WebRequest]::Create('https://lenovobattery2014.orderz.com') | |
$HTTP_Request.Timeout = 10000 | |
try { | |
$HTTP_Response = $HTTP_Request.GetResponse() | |
$HTTP_Response.Close() | |
} catch [System.Net.WebException] { | |
$HTTP_Response = $_.Exception.Response | |
} | |
$HTTP_Status = [int]$HTTP_Response.StatusCode | |
If ($HTTP_Status -eq 200) { | |
Write-Log "The site is reachable" | |
} | |
Else { | |
Write-Log "The site is unreachable, error $HTTP_Status" | |
Exit-Script -ExitCode "1" | |
} | |
$message = @" | |
This is an important safety message from ***YOUR COMPANY NAME HERE***. | |
The manufacturer of this laptop has initiated a recall of a specific batch of laptop batteries. Affected batteries may overheat, posing a fire hazard. | |
To verify whether the battery in this laptop is affected, a program will be run on your computer. If replacement is not required, you will see a dialog box saying "Your battery is not affected" or a web page saying "Your battery is not eligible for replacement." | |
If the battery requires replacement, a web page will open with a message saying "Your battery is eligible for replacement". Click "Continue" and fill out the form to request the replacement battery. Until the replacement battery arrives, you should shut down the laptop, remove the battery, and only use the laptop with the AC adapter connected. | |
Please click OK to start the test. | |
"@ | |
Show-DialogBox -Text $message -Title "Lenovo Battery Recall 2014" -Icon "Exclamation" | |
Show-InstallationProgress -Topmost $false | |
#*=============================================== | |
#* INSTALLATION | |
$installPhase = "Installation" | |
#*=============================================== | |
# Perform installation tasks here | |
Execute-Process -FilePath "LenovoBattery.exe" -Arguments "/silent" | |
#*=============================================== | |
#* POST-INSTALLATION | |
$installPhase = "Post-Installation" | |
#*=============================================== | |
# Perform post-installation tasks here | |
# Uninstall the program | |
$dir = (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0] + "\Lenovo Battery Utility 2014\unins000.exe" | |
Execute-Process -FilePath $dir -Arguments "/SILENT" | |
# Display a message at the end of the install | |
$message2 = @" | |
The test has completed. | |
If your laptop was supplied with a spare battery, you will need to run this test again with the other battery installed. Please contact the IT Service Desk for further assistance. | |
If you have any questions or concerns, please contact the IT Service Desk. | |
"@ | |
Show-DialogBox -Text $message2 -Title "Lenovo Battery Recall 2014" -Icon "Information" | |
#*=============================================== | |
#* UNINSTALLATION | |
} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation" | |
#*=============================================== | |
# No uninstallation required | |
#*=============================================== | |
#* END SCRIPT BODY | |
} } Catch { $exceptionMessage = "$($_.Exception.Message) `($($_.ScriptStackTrace)`)"; Write-Log "$exceptionMessage"; Show-DialogBox -Text $exceptionMessage -Icon "Stop"; Exit-Script -ExitCode 1 } # Catch any errors in this script | |
Exit-Script -ExitCode 0 # Otherwise call the Exit-Script function to perform final cleanup operations | |
#*=============================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment