Guest User

Untitled

a guest
Jan 22nd, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.40 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. This script performs the installation or uninstallation of an application(s).
  4. .DESCRIPTION
  5. The script is provided as a template to perform an install or uninstall of an application(s).
  6. The script either performs an "Install" deployment type or an "Uninstall" deployment type.
  7. The install deployment type is broken down into 3 main sections/phases: Pre-Install, Install, and Post-Install.
  8. The script dot-sources the AppDeployToolkitMain.ps1 script which contains the logic and functions required to install or uninstall an application.
  9. .PARAMETER DeploymentType
  10. The type of deployment to perform. Default is: Install.
  11. .PARAMETER DeployMode
  12. Specifies whether the installation should be run in Interactive, Silent, or NonInteractive mode. Default is: Interactive. Options: Interactive = Shows dialogs, Silent = No dialogs, NonInteractive = Very silent, i.e. no blocking apps. NonInteractive mode is automatically set if it is detected that the process is not user interactive.
  13. .PARAMETER AllowRebootPassThru
  14. 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.
  15. .PARAMETER TerminalServerMode
  16. Changes to "user install mode" and back to "user execute mode" for installing/uninstalling applications for Remote Destkop Session Hosts/Citrix servers.
  17. .PARAMETER DisableLogging
  18. Disables logging to file for the script. Default is: $false.
  19. .EXAMPLE
  20. Deploy-Application.ps1
  21. .EXAMPLE
  22. Deploy-Application.ps1 -DeployMode 'Silent'
  23. .EXAMPLE
  24. Deploy-Application.ps1 -AllowRebootPassThru -AllowDefer
  25. .EXAMPLE
  26. Deploy-Application.ps1 -DeploymentType Uninstall
  27. .NOTES
  28. Toolkit Exit Code Ranges:
  29. 60000 - 68999: Reserved for built-in exit codes in Deploy-Application.ps1, Deploy-Application.exe, and AppDeployToolkitMain.ps1
  30. 69000 - 69999: Recommended for user customized exit codes in Deploy-Application.ps1
  31. 70000 - 79999: Recommended for user customized exit codes in AppDeployToolkitExtensions.ps1
  32. .LINK
  33. http://psappdeploytoolkit.com
  34. #>
  35. [CmdletBinding()]
  36. Param (
  37. [Parameter(Mandatory=$false)]
  38. [ValidateSet('Install','Uninstall')]
  39. [string]$DeploymentType = 'Install',
  40. [Parameter(Mandatory=$false)]
  41. [ValidateSet('Interactive','Silent','NonInteractive')]
  42. [string]$DeployMode = 'Silent',
  43. [Parameter(Mandatory=$false)]
  44. [switch]$AllowRebootPassThru = $false,
  45. [Parameter(Mandatory=$false)]
  46. [switch]$TerminalServerMode = $false,
  47. [Parameter(Mandatory=$false)]
  48. [switch]$DisableLogging = $false
  49. )
  50.  
  51. Try {
  52. ## Set the script execution policy for this process
  53. Try { Set-ExecutionPolicy -ExecutionPolicy 'ByPass' -Scope 'Process' -Force -ErrorAction 'Stop' } Catch {}
  54.  
  55. ##*===============================================
  56. ##* VARIABLE DECLARATION
  57. ##*===============================================
  58. ## Variables: Application
  59. [string]$appVendor = 'Microsoft'
  60. [string]$appName = 'Internet Explorer'
  61. [string]$appVersion = '11'
  62. [string]$appArch = 'x64'
  63. [string]$appLang = 'EN'
  64. [string]$appRevision = '01'
  65. [string]$appScriptVersion = '1.0.0'
  66. [string]$appScriptDate = '08/17/2015'
  67. [string]$appScriptAuthor = '<author name>'
  68. ##*===============================================
  69.  
  70. ##* Do not modify section below
  71. #region DoNotModify
  72.  
  73. ## Variables: Exit Code
  74. [int32]$mainExitCode = 0
  75.  
  76. ## Variables: Script
  77. [string]$deployAppScriptFriendlyName = 'Deploy Application'
  78. [version]$deployAppScriptVersion = [version]'3.6.5'
  79. [string]$deployAppScriptDate = '08/17/2015'
  80. [hashtable]$deployAppScriptParameters = $psBoundParameters
  81.  
  82. ## Variables: Environment
  83. If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
  84. [string]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent
  85.  
  86. ## Dot source the required App Deploy Toolkit Functions
  87. Try {
  88. [string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
  89. If (-not (Test-Path -LiteralPath $moduleAppDeployToolkitMain -PathType 'Leaf')) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
  90. If ($DisableLogging) { . $moduleAppDeployToolkitMain -DisableLogging } Else { . $moduleAppDeployToolkitMain }
  91. }
  92. Catch {
  93. If ($mainExitCode -eq 0){ [int32]$mainExitCode = 60008 }
  94. Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
  95. ## Exit the script, returning the exit code to SCCM
  96. If (Test-Path -LiteralPath 'variable:HostInvocation') { $script:ExitCode = $mainExitCode; Exit } Else { Exit $mainExitCode }
  97. }
  98.  
  99. #endregion
  100. ##* Do not modify section above
  101. ##*===============================================
  102. ##* END VARIABLE DECLARATION
  103. ##*===============================================
  104.  
  105. If ($deploymentType -ine 'Uninstall') {
  106. ##*===============================================
  107. ##* PRE-INSTALLATION
  108. ##*===============================================
  109. [string]$installPhase = 'Pre-Installation'
  110.  
  111. ## Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
  112. Get-Process "iexplore" | Stop-Process
  113.  
  114. ## Show Progress Message (with the default message)
  115. #Show-InstallationProgress
  116.  
  117. ## <Perform Pre-Installation tasks here>
  118.  
  119.  
  120. ##*===============================================
  121. ##* INSTALLATION
  122. ##*===============================================
  123. [string]$installPhase = 'Installation'
  124.  
  125. ## Handle Zero-Config MSI Installations
  126. If ($useDefaultMsi) {
  127. [hashtable]$ExecuteDefaultMSISplat = @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  128. Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
  129. }
  130.  
  131. ## <Perform Installation tasks here>
  132. Execute-MSI -action install -path $dirFiles\FLAT\AMD64_WIN7\EN-US\IE11-Setup-Full.MSI
  133.  
  134. ##*===============================================
  135. ##* POST-INSTALLATION
  136. ##*===============================================
  137. [string]$installPhase = 'Post-Installation'
  138.  
  139. ## <Perform Post-Installation tasks here>
  140. Restart-Computer -Force
  141. ## Display a message at the end of the install
  142. #If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'The program has been installed successfully.' -ButtonRightText 'OK' -Icon Information -NoWait }
  143. }
  144. ElseIf ($deploymentType -ieq 'Uninstall')
  145. {
  146. ##*===============================================
  147. ##* PRE-UNINSTALLATION
  148. ##*===============================================
  149. [string]$installPhase = 'Pre-Uninstallation'
  150.  
  151. ## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
  152. Show-InstallationWelcome -CloseApps 'iexplore' -CloseAppsCountdown 60
  153.  
  154. ## Show Progress Message (with the default message)
  155. Show-InstallationProgress
  156.  
  157. ## <Perform Pre-Uninstallation tasks here>
  158.  
  159.  
  160. ##*===============================================
  161. ##* UNINSTALLATION
  162. ##*===============================================
  163. [string]$installPhase = 'Uninstallation'
  164.  
  165. ## Handle Zero-Config MSI Uninstallations
  166. If ($useDefaultMsi) {
  167. [hashtable]$ExecuteDefaultMSISplat = @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  168. Execute-MSI @ExecuteDefaultMSISplat
  169. }
  170.  
  171. # <Perform Uninstallation tasks here>
  172.  
  173.  
  174. ##*===============================================
  175. ##* POST-UNINSTALLATION
  176. ##*===============================================
  177. [string]$installPhase = 'Post-Uninstallation'
  178.  
  179. ## <Perform Post-Uninstallation tasks here>
  180.  
  181.  
  182. }
  183.  
  184. ##*===============================================
  185. ##* END SCRIPT BODY
  186. ##*===============================================
  187.  
  188. ## Call the Exit-Script function to perform final cleanup operations
  189. Exit-Script -ExitCode $mainExitCode
  190. }
  191. Catch {
  192. [int32]$mainExitCode = 60001
  193. [string]$mainErrorMessage = "$(Resolve-Error)"
  194. Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
  195. Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
  196. Exit-Script -ExitCode $mainExitCode
  197. }
Add Comment
Please, Sign In to add comment