Guest User

Untitled

a guest
Jan 22nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = 'Adobe'
  60.     [string]$appName = 'Flash'
  61.     [string]$appVersion = '20'
  62.     [string]$appArch = ''
  63.     [string]$appLang = 'EN'
  64.     [string]$appRevision = '01'
  65.     [string]$appScriptVersion = '1.0.0'
  66.     [string]$appScriptDate = '12/18/2015'
  67.     [string]$appScriptAuthor = 'BPL'
  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 & FF if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
  112.         #Show-InstallationWelcome -CloseApps 'iexplore,firefox' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt
  113.        
  114.         ## Show Progress Message (with the default message)
  115.         Show-InstallationProgress
  116.        
  117.         ## <Perform Pre-Installation tasks here>chro
  118.         #Get-Process iexplore | Stop-Process
  119. #if (Get-Process "firefox"){
  120. #Exit-Script -ExitCode $mainExitCode
  121. #}
  122. #if (Get-Process "iexplore"){
  123. #Exit-Script -ExitCode $mainExitCode
  124. #}
  125.         #Get-Process firefox | Stop-Process
  126.         Get-Process iexplore | Stop-Process
  127.         Get-Process firefox | Stop-Process
  128.         remove-msiapplications -name 'Adobe Flash'
  129.  
  130.         copy-file -path "$dirFiles\mms.cfg" -Destination "$envSystemRoot\system32\Macromed\Flash\mms.cfg"
  131.         copy-file -path "$dirFiles\mms.cfg" -destination "$envSystemRoot\SysWow64\Macromed\Flash\mms.cfg"
  132.        
  133.        
  134.         ##*===============================================
  135.         ##* INSTALLATION
  136.         ##*===============================================
  137.         [string]$installPhase = 'Installation'
  138.        
  139.         ## Handle Zero-Config MSI Installations
  140.         If ($useDefaultMsi) {
  141.             [hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  142.             Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
  143.         }
  144.        
  145.         ## <Perform Installation tasks here>
  146.         execute-msi -action install -path install_flash_player_20_active_x.msi
  147.         execute-msi -action install -path install_flash_player_20_plugin.msi
  148.        
  149.         ##*===============================================
  150.         ##* POST-INSTALLATION
  151.         ##*===============================================
  152.         [string]$installPhase = 'Post-Installation'
  153.        
  154.         ## <Perform Post-Installation tasks here>
  155.        
  156.         ## Display a message at the end of the install
  157.         #If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'You can customize text to appear at the end of an install or remove it completely for unattended installations.' -ButtonRightText 'OK' -Icon Information -NoWait }
  158.     }
  159.     ElseIf ($deploymentType -ieq 'Uninstall')
  160.     {
  161.         ##*===============================================
  162.         ##* PRE-UNINSTALLATION
  163.         ##*===============================================
  164.         [string]$installPhase = 'Pre-Uninstallation'
  165.        
  166.         ## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
  167.         Show-InstallationWelcome -CloseApps 'iexplore' -CloseAppsCountdown 60
  168.        
  169.         ## Show Progress Message (with the default message)
  170.         Show-InstallationProgress
  171.        
  172.         ## <Perform Pre-Uninstallation tasks here>
  173.        
  174.        
  175.         ##*===============================================
  176.         ##* UNINSTALLATION
  177.         ##*===============================================
  178.         [string]$installPhase = 'Uninstallation'
  179.        
  180.         ## Handle Zero-Config MSI Uninstallations
  181.         If ($useDefaultMsi) {
  182.             [hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  183.             Execute-MSI @ExecuteDefaultMSISplat
  184.         }
  185.        
  186.         # <Perform Uninstallation tasks here>
  187.        
  188.        
  189.         ##*===============================================
  190.         ##* POST-UNINSTALLATION
  191.         ##*===============================================
  192.         [string]$installPhase = 'Post-Uninstallation'
  193.        
  194.         ## <Perform Post-Uninstallation tasks here>
  195.        
  196.        
  197.     }
  198.    
  199.     ##*===============================================
  200.     ##* END SCRIPT BODY
  201.     ##*===============================================
  202.    
  203.     ## Call the Exit-Script function to perform final cleanup operations
  204.     Exit-Script -ExitCode $mainExitCode
  205. }
  206. Catch {
  207.     [int32]$mainExitCode = 60001
  208.     [string]$mainErrorMessage = "$(Resolve-Error)"
  209.     Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
  210.     Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
  211.     Exit-Script -ExitCode $mainExitCode
  212. }
Add Comment
Please, Sign In to add comment