Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
62
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.     powershell.exe -Command "& { & '.\Deploy-Application.ps1' -DeployMode 'Silent'; Exit $LastExitCode }"
  21. .EXAMPLE
  22.     powershell.exe -Command "& { & '.\Deploy-Application.ps1' -AllowRebootPassThru; Exit $LastExitCode }"
  23. .EXAMPLE
  24.     powershell.exe -Command "& { & '.\Deploy-Application.ps1' -DeploymentType 'Uninstall'; Exit $LastExitCode }"
  25. .EXAMPLE
  26.     Deploy-Application.exe -DeploymentType "Install" -DeployMode "Silent"
  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 = 'Interactive',
  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 = 'Creative Cloud'
  61.     [string]$appVersion = '2017'
  62.     [string]$appArch = 'x64'
  63.     [string]$appLang = 'EN'
  64.     [string]$appRevision = '01'
  65.     [string]$appScriptVersion = '1.0.0'
  66.     [string]$appScriptDate = '06/19/2017'
  67.     [string]$appScriptAuthor = 'mbado'
  68.     ##*===============================================
  69.     ## Variables: Install Titles (Only set here to override defaults set by the toolkit)
  70.     [string]$installName = ''
  71.     [string]$installTitle = ''
  72.    
  73.     ##* Do not modify section below
  74.     #region DoNotModify
  75.    
  76.     ## Variables: Exit Code
  77.     [int32]$mainExitCode = 0
  78.    
  79.     ## Variables: Script
  80.     [string]$deployAppScriptFriendlyName = 'Deploy Application'
  81.     [version]$deployAppScriptVersion = [version]'3.6.9'
  82.     [string]$deployAppScriptDate = '02/12/2017'
  83.     [hashtable]$deployAppScriptParameters = $psBoundParameters
  84.    
  85.     ## Variables: Environment
  86.     If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
  87.     [string]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent
  88.    
  89.     ## Dot source the required App Deploy Toolkit Functions
  90.     Try {
  91.         [string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
  92.         If (-not (Test-Path -LiteralPath $moduleAppDeployToolkitMain -PathType 'Leaf')) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
  93.         If ($DisableLogging) { . $moduleAppDeployToolkitMain -DisableLogging } Else { . $moduleAppDeployToolkitMain }
  94.     }
  95.     Catch {
  96.         If ($mainExitCode -eq 0){ [int32]$mainExitCode = 60008 }
  97.         Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
  98.         ## Exit the script, returning the exit code to SCCM
  99.         If (Test-Path -LiteralPath 'variable:HostInvocation') { $script:ExitCode = $mainExitCode; Exit } Else { Exit $mainExitCode }
  100.     }
  101.    
  102.     #endregion
  103.     ##* Do not modify section above
  104.     ##*===============================================
  105.     ##* END VARIABLE DECLARATION
  106.     ##*===============================================
  107.        
  108.     If ($deploymentType -ine 'Uninstall') {
  109.         ##*===============================================
  110.         ##* PRE-INSTALLATION
  111.         ##*===============================================
  112.         [string]$installPhase = 'Pre-Installation'
  113.        
  114.         ## 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
  115.         #Show-InstallationWelcome -CloseApps 'iexplore' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt
  116.        
  117.         ## Show Progress Message (with the default message)
  118.         Show-InstallationWelcome -CloseApps 'Creative Cloud,CCLibrary,AdobeUpdateService,Adobe CEF Helper,AdobeIPCBroker,Adobe Desktop Service' -Silent
  119.        
  120.         ## Show Progress Message (with the default message)
  121.         Show-InstallationProgress "Installing $installTitle, please wait..."
  122.        
  123.         ## <Perform Pre-Installation tasks here>
  124.         Execute-Process -Path "$dirFiles\Exceptions\ExceptionDeployer.exe" -Parameters "--workflow=install --mode=pre"
  125.        
  126.         ##*===============================================
  127.         ##* INSTALLATION
  128.         ##*===============================================
  129.         [string]$installPhase = 'Installation'
  130.        
  131.         ## Handle Zero-Config MSI Installations
  132.         If ($useDefaultMsi) {
  133.             [hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  134.             Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
  135.         }
  136.        
  137.         ## <Perform Installation tasks here>
  138.         Execute-MSI -Action Install -Path "$dirFiles\Build\Creative Cloud.msi" -Parameters "/qn /norestart /log output.log"
  139.        
  140.         ##*===============================================
  141.         ##* POST-INSTALLATION
  142.         ##*===============================================
  143.         [string]$installPhase = 'Post-Installation'
  144.        
  145.         ## <Perform Post-Installation tasks here>
  146.         Execute-Process -Path "$dirFiles\Exceptions\ExceptionDeployer.exe" -Parameters "--workflow=install --mode=post"
  147.  
  148.  
  149.         ## Run the updater
  150.         Execute-Process -Path "${env:ProgramFiles(x86)}\Common Files\Adobe\OOBE_Enterprise\RemoteUpdateManager\RemoteUpdateManager.exe"
  151.  
  152.         ## Delete Desktop Shortcuts
  153.         $users = Get-ChildItem c:\Users
  154.         foreach ($user in $users){
  155.             Remove-Item -Path "C:\Users\$user\Desktop\Adobe Lightroom.lnk" -Force -ErrorAction SilentlyContinue
  156.             Remove-Item -Path "C:\Users\$user\Desktop\Adobe Fuse CC (Preview).lnk" -Force -ErrorAction SilentlyContinue
  157.             Remove-Item -Path "C:\Users\$user\Desktop\Adobe Fuse CC (Beta).lnk" -Force -ErrorAction SilentlyContinue
  158.  
  159.         }
  160.  
  161.         Remove-Item -Path "$env:Public\Desktop\Adobe Creative Cloud.lnk" -Force -ErrorAction SilentlyContinue
  162.         Remove-Item -Path "$env:Public\Desktop\Adobe Scout CC.lnk" -Force -ErrorAction SilentlyContinue
  163.  
  164.         ## Enable updates
  165.         #Copy-Item -Path "$dirSupportFiles\AdobeUpdaterAdminPrefs.dat" -Destination "${env:ProgramFiles(x86)}\Common Files\Adobe\AAMUpdaterInventory\1.0" -Force
  166.        
  167.         ## Display a message at the end of the install
  168.         If (-not $useDefaultMsi) {
  169.             #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
  170.         }
  171.     }
  172.     ElseIf ($deploymentType -ieq 'Uninstall')
  173.     {
  174.         ##*===============================================
  175.         ##* PRE-UNINSTALLATION
  176.         ##*===============================================
  177.         [string]$installPhase = 'Pre-Uninstallation'
  178.        
  179.         ## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
  180.         #Show-InstallationWelcome -CloseApps 'iexplore' -CloseAppsCountdown 60
  181.        
  182.         ## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
  183.         Show-InstallationWelcome -CloseApps 'Creative Cloud,CCLibrary,AdobeUpdateService,Adobe CEF Helper,AdobeIPCBroker,Adobe Desktop Service' -Silent
  184.        
  185.         ## Show Progress Message (with the default message)
  186.         Show-InstallationProgress "Uninstalling $installTitle, please wait..."
  187.        
  188.         ## <Perform Pre-Uninstallation tasks here>
  189.        
  190.        
  191.         ##*===============================================
  192.         ##* UNINSTALLATION
  193.         ##*===============================================
  194.         [string]$installPhase = 'Uninstallation'
  195.        
  196.         ## Handle Zero-Config MSI Uninstallations
  197.         If ($useDefaultMsi) {
  198.             [hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  199.             Execute-MSI @ExecuteDefaultMSISplat
  200.         }
  201.        
  202.         # <Perform Uninstallation tasks here>
  203.         Execute-MSI -Action Uninstall "$dirFiles\Build\Creative Cloud.msi" -Parameters '/qn /norestart /log output.log' -ContinueOnError $true
  204.        
  205.         #Uninstall Adobe Gaming SDK 1.4
  206.         Remove-MSIApplications -Name 'Adobe Gaming SDK 1.4'
  207.        
  208.         #Uninstall Adobe Help Manager
  209.         Remove-MSIApplications -Name 'Adobe Help Manager'
  210.        
  211.         #Uninstall Adobe Scout CC
  212.         Remove-MSIApplications -Name 'Adobe Scout CC'
  213.  
  214.         ##*===============================================
  215.         ##* POST-UNINSTALLATION
  216.         ##*===============================================
  217.         [string]$installPhase = 'Post-Uninstallation'
  218.        
  219.         ## <Perform Post-Uninstallation tasks here>
  220.        
  221.        
  222.     }
  223.    
  224.     ##*===============================================
  225.     ##* END SCRIPT BODY
  226.     ##*===============================================
  227.    
  228.     ## Call the Exit-Script function to perform final cleanup operations
  229.     Exit-Script -ExitCode $mainExitCode
  230. }
  231. Catch {
  232.     [int32]$mainExitCode = 60001
  233.     [string]$mainErrorMessage = "$(Resolve-Error)"
  234.     Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
  235.     Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
  236.     Exit-Script -ExitCode $mainExitCode
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement