Advertisement
Guest User

Untitled

a guest
Oct 30th, 2017
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.27 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. 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 = 'Microsoft'
  60. [string]$appName = 'Office 365'
  61. [string]$appVersion = ''
  62. [string]$appArch = ''
  63. [string]$appLang = 'EN'
  64. [string]$appRevision = '01'
  65. [string]$appScriptVersion = '1.0.0'
  66. [string]$appScriptDate = '02/12/2017'
  67. [string]$appScriptAuthor = '<author name>'
  68. ##*===============================================
  69. ## Variables: Install Titles (Only set here to override defaults set by the toolkit)
  70. [string]$installName = 'Office 365 Proplus 2016 Fast Insider'
  71. [string]$installTitle = 'Installing Office 365 Proplus 2016 Fast Insider'
  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.  
  115.  
  116.  
  117. #[string] $dirOfficeC2R = Join-Path -Path "$envProgramFilesX86" -ChildPath "Microsoft Office"
  118.  
  119. Show-InstallationPrompt `
  120. -Message "This will install Microsoft Office 365 ProPlus 2016 for you. Please note that the installation can take up to 30 minutes.`nAll previous Office versions will be uninstalled first.`nSave all your work and click OK to continue." `
  121. -ButtonRightText "OK" `
  122. -Icon Information `
  123. -Timeout 120 `
  124. -ExitOnTimeout $false
  125.  
  126. Start-Sleep 5
  127.  
  128.  
  129. ## 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
  130. Show-InstallationWelcome -CloseApps 'ose,osppsvc,sppsvc,msoia,excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio,iexplore' -CloseAppsCountdown 900 -CheckDiskSpace -PersistPrompt
  131.  
  132. ## Show Progress Message
  133. Show-InstallationProgress -StatusMessage "Office 365 Installation in Progress…The Installation may take up to 30 minutes to complete." -TopMost $False
  134.  
  135. ## Display Pre-Install cleanup status
  136. Show-InstallationProgress -StatusMessage "Performing Pre-Install cleanup. Removing Prior Office Versions… This may take some time. Please wait…"
  137.  
  138. # Remove any previous version of Office (if required)
  139. #[string[]]$officeExecutables = 'excel.exe', 'groove.exe', 'infopath.exe', 'onenote.exe', 'outlook.exe', 'mspub.exe', 'powerpnt.exe', 'winword.exe'
  140.  
  141.  
  142. #construct offscrub path
  143. #$Offscrubc2r = '"' + $dirSupportFiles + '\OffScrubc2r.vbs' + '"'
  144.  
  145. # ForEach ($officeExecutable in $officeExecutables) {
  146. # If (Test-Path -Path (Join-Path -Path $dirOfficeC2R -ChildPath "root\Office16\$officeExecutable") -PathType Leaf) {
  147. # Write-Log -Message 'Microsoft Office 2016 C2R was detected. Will be uninstalled.' -Source $deployAppScriptFriendlyName
  148. # Execute-Process -Path "cscript.exe" -Parameters "$Offscrubc2r ALL /S /Q /NoCancel /Bypass 1" -WindowStyle Hidden -IgnoreExitCodes '1,2,3,42,34,67'
  149. # Break
  150. # }
  151. #}
  152.  
  153.  
  154. ## <Perform Pre-Installation tasks here>
  155.  
  156. Show-InstallationProgress -StatusMessage 'Removing previous version of Office 365. This may take some time. Please wait...' -TopMost $True
  157. Execute-Process -Path "$dirSupportFiles\Setup.exe" -Parameters "/Configure uninstall.xml"
  158.  
  159.  
  160. ##*===============================================
  161. ##* INSTALLATION
  162. ##*===============================================
  163. [string]$installPhase = 'Installation'
  164.  
  165.  
  166. Show-InstallationProgress -StatusMessage 'Installing Office 365 Proplus 2016 Fast Insider. This may take some time. Please wait...' -TopMost $True
  167. Execute-Process -Path "$dirFiles\Setup.exe" -Parameters "/Configure configuration.xml"
  168.  
  169.  
  170. ## Handle Zero-Config MSI Installations
  171. ##If ($useDefaultMsi) {
  172. ## [hashtable]$ExecuteDefaultMSISplat = @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  173. ## Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
  174. ##}
  175.  
  176. ## <Perform Installation tasks here>
  177.  
  178.  
  179. & cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint 2016.lnk"
  180. & cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook 2016.lnk"
  181. & cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"
  182. & cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\skype For Business 2016.lnk"
  183. & cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel 2016.lnk"
  184.  
  185.  
  186.  
  187.  
  188.  
  189. ##*===============================================
  190. ##* POST-INSTALLATION
  191. ##*===============================================
  192. [string]$installPhase = 'Post-Installation'
  193.  
  194. ## <Perform Post-Installation tasks here>
  195.  
  196. #Show-InstallationProgress -StatusMessage 'Pinning Office 365 Apps to the TaskBar' -TopMost $True
  197.  
  198. #& cscript.exe "C:\Windows\ccmcache\10\SupportFiles\pintotaskbar.vbs" "C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE"
  199. #& cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"
  200. #& cscript.exe "$dirSupportFiles\pintotaskbar.vbs" "C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"
  201.  
  202.  
  203.  
  204.  
  205. ## Display a message at the end of the install
  206. If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'Office 365 ProPlus 2016 Fast Insider is complete.' -ButtonRightText 'OK' -Icon Information -NoWait }
  207. }
  208. ElseIf ($deploymentType -ieq 'Uninstall')
  209. {
  210. ##*===============================================
  211. ##* PRE-UNINSTALLATION
  212. ##*===============================================
  213. [string]$installPhase = 'Pre-Uninstallation'
  214.  
  215. ## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
  216. Show-InstallationWelcome -CloseApps 'iexplore' -CloseAppsCountdown 60
  217.  
  218. ## Show Progress Message (with the default message)
  219. Show-InstallationProgress
  220.  
  221. ## <Perform Pre-Uninstallation tasks here>
  222.  
  223.  
  224. ##*===============================================
  225. ##* UNINSTALLATION
  226. ##*===============================================
  227. [string]$installPhase = 'Uninstallation'
  228.  
  229. ## Handle Zero-Config MSI Uninstallations
  230. If ($useDefaultMsi) {
  231. [hashtable]$ExecuteDefaultMSISplat = @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
  232. Execute-MSI @ExecuteDefaultMSISplat
  233. }
  234.  
  235. # <Perform Uninstallation tasks here>
  236.  
  237.  
  238. ##*===============================================
  239. ##* POST-UNINSTALLATION
  240. ##*===============================================
  241. [string]$installPhase = 'Post-Uninstallation'
  242.  
  243. ## <Perform Post-Uninstallation tasks here>
  244.  
  245.  
  246. }
  247.  
  248. ##*===============================================
  249. ##* END SCRIPT BODY
  250. ##*===============================================
  251.  
  252. ## Call the Exit-Script function to perform final cleanup operations
  253. Exit-Script -ExitCode $mainExitCode
  254. }
  255. Catch {
  256. [int32]$mainExitCode = 60001
  257. [string]$mainErrorMessage = "$(Resolve-Error)"
  258. Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
  259. Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
  260. Exit-Script -ExitCode $mainExitCode
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement