Newbie...Trouble running script. Need some help!

Topics: Archive - General
Dec 13, 2013 at 3:00 PM
I have the following code that I trying to run. It is not running at all. I can't figure out why. ANy help would be great.
    This script performs the installation or uninstallation of an application(s).  
    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,
    Deploy-Application.ps1 -DeploymentType "Silent"
    Deploy-Application.ps1 -AllowRebootPassThru -AllowDefer
    Deploy-Application.ps1 -Uninstall 
.PARAMETER DeploymentType
    The type of deployment to perform. [Default is "Install"]
    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.

Write-Log "WORKING"

Param (
    [string] $DeploymentType = "Install",
    [string] $DeployMode = "Interactive",
    [switch] $AllowRebootPassThru = $false,

Try {

# Variables: Application

$appVendor = "Microsoft"
$appName = "Office"
$appVersion = "2013"
$appArch = "x86"
$appLang = "EN"
$appRevision = ""
$appScriptVersion = "1.0"
$appScriptDate = "12/13/2013"
$appScriptAuthor = "Jamie Thoenen"

# Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Deploy Application"
$deployAppScriptVersion = "3.0.6"
$deployAppScriptDate = "10/10/2013"
$deployAppScriptParameters = $psBoundParameters

# Variables: Environment
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Dot source the App Deploy Toolkit Functions

# Office Directory
$dirOffice = Join-Path "$envProgramFilesX86" "Microsoft Office"


If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
    #Check to see if Office 2013 is already installed
        IF (Get-InstalledApplication -Name "Microsoft Office Professional Plus 2013" -eq $True)
            {Write-Log "Microsoft Office 2013 was detected. Program will now exit."
                Exit-Script -ExitCode 0} 

    # Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals
    Show-InstallationWelcome -CloseApps "excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio" -AllowDefer -DeferTimes 3

        # Display Pre-Install cleanup status
        Show-InstallationProgress "Performing Pre-Install cleanup. This may take some time. Please wait..."

        # Remove any previous version of Office (if required)
        $officeExecutables = @("excel.exe", "groove.exe", "onenote.exe", "infopath.exe", "onenote.exe", "outlook.exe", "mspub.exe", "powerpnt.exe", "winword.exe", "winproj.exe" ,"visio.exe")
        ForEach ($officeExecutable in $officeExecutables) {
            If (Test-Path (Join-Path $dirOffice "Office12\$officeExecutable")) { 
                Write-Log "Microsoft Office 2007 was detected. Will be uninstalled."
                Execute-Process -FilePath "CScript.Exe" -Arguments "`"$dirSupportFiles\OffScrub07.vbs`" ClientAll /S /Q /NoCancel" -WindowStyle Hidden -IgnoreExitCodes "1,2,3"
        ForEach ($officeExecutable in $officeExecutables) {
            If (Test-Path (Join-Path $dirOffice "Office14\$officeExecutable")) { 
                Write-Log "Microsoft Office 2010 was detected. Will be uninstalled."
                Execute-Process -FilePath "CScript.Exe" -Arguments "`"$dirSupportFiles\OffScrub10.vbs`" ClientAll /S /Q /NoCancel" -WindowStyle Hidden -IgnoreExitCodes "1,2,3"

$installPhase = "Installation"
    #Install Office 2013
    Execute-Process -FilePath "$dirFiles\Office2013\Setup.exe"

$installPhase = "Post-Installation"

    # Prompt for a restart (if running as a user, not installing components and not running on a server)

} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"

    # Show Welcome Message, close applications if required with a 60 second countdown before automatically closing
    Show-InstallationWelcome -CloseApps "excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio"

    # Show Progress Message (with the default message)

    Execute-Process -FilePath "CScript.Exe" -Arguments "`"$dirSupportFiles\OffScrub10.vbs`" ClientAll /S /Q /NoCancel" -WindowStyle Hidden -IgnoreExitCodes "1,2,3"

} } 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
Dec 13, 2013 at 3:19 PM
You're Write-Log "WORKING" line needs to be removed, it won't work before the Param section and breaks the whole script.

Also, you have an extra close bracket on line 132, underneath Show-InstallationRestartPrompt - which will also break things.

Marked as answer by rednecknerd on 12/20/2013 at 7:08 AM
Dec 20, 2013 at 2:08 PM
Thanks. I have it working now.