Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Install application script used by MDT

$
0
0

Hallo all,

I'm quite new to Powershell so don't laugh of my script build, but working on a script that will install an application and write the Exitcode to a log file.

I would like to hear your opinion for my apposed. Would there be a better way to install the application?

Would you normally do a check in the script if the application is installed correctly before moving down the script? More if I need to build more into the script after the application install step.

Here is my script:

# Imports MDT Powershell Module for testing outside of MDT

# Import-Module .\ZTIUtility.psm1

 

# Determine where to do the logging 

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 

$logPath = $tsenv.Value("LogPath") 

$logFile = "$logPath\$($myInvocation.MyCommand).log"

 

# Start the logging 

Start-Transcript $logFile

Write-Output "Logging to $logFile"

 

# Start Main Code Here

 

# Define each variables

$AppName = '<<xx-application>>'

$Appx64 = ".\source\jre1.8.0_51_x64.msi"

$Appx86 = ".\source\jre1.8.0_51_x86.msi"

$psArchitecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture

$Parameters = "/q"

 

# Checks that each source files are available in sub directory 

If (((Test-path "$Appx64","$Appx86") -eq $False)) {

    Write-Output "One of the source files is missing, unable to install."

    Exit

}

Else {

    Write-Output "Source files found - will start the installation now"

}

 

# Installs <<xx-application>> x64 and write logs to the DeploymentLogs directory

Write-Output "Starting installation of $AppName"

# Starts a process of installation

If ($psArchitecture -eq '64-bit') {

    Write-Output "Installing $AppName : $Appx64"

    $ProcessX64 = (Start-Process "$Appx64" -ArgumentList $Parameters -Wait -Passthru).ExitCode

}

ELSE {

    # Installs <<xx-application>> x86 and write logs to the DeploymentLogs directory

    # Starts a process of installation

    If (($psArchitecture -eq '86-bit') -or ($psArchitecture -eq '32-bit')) {

    Write-Output "Installing $AppName : $Appx86"

    $ProcessX86 = (Start-Process "$Appx86" -ArgumentList $Parameters -Wait -Passthru).ExitCode

    }

}

 

# Write to BDD.log if the whole installation succeeded

If (($ProcessX64.ExitCode -ne 0) -or ($ProcessX86.ExitCode -ne 0)) {

    Write-Output "$AppName has been installed succesfully"

}

ELSE {

    Write-Output "Installation failed - check your BDD.log for more info"

    Write-Output "Installer exit code $($ProcessX64.ExitCode) $($ProcessX86.ExitCode)"

}

 

# Stop logging 

Stop-Transcript

Looking forward to read your suggestion.

BR,

Daniel 


Viewing all articles
Browse latest Browse all 6937

Trending Articles