Application Deployment using PowerShell Script

An essential guide for IT professionals to automate the silent deployment of applications using MSI installers.

In this Guide:

Introduction

Installing software on multiple computers is a boring and resource intensive task. This guide provides a PowerShell application deployment script to automate the process of installing applications silently using MSI installers. For IT pros, system admins and MSPs this script means consistent installs, less manual work and large scale software deployment without user interaction. This is a fundamental tool for any modern IT automation.

Background

Traditional software installs require a user to click through a series of prompts which is not possible when deploying software across an entire organization. The need for a silent MSI install is critical in enterprise environments where applications need to be deployed to hundreds or thousands of machines automatically, often during off hours. This script solves the problem of manual intervention by using the command line capabilities of the Windows Installer (msiexec.exe). It allows you to automate software install with a standardized non interactive process, no user popups and every install will be done correctly.

Script

Here is the script. Save this as a .ps1 file.

Deploy-Application.ps1
Copy to clipboard
# -----------------------------------------------------------------------------
# Script Name: Deploy-Application.ps1
# Description: Automates the silent deployment of applications using an MSI installer.

# -----------------------------------------------------------------------------

# PARAMETERS:
# -MsiPath: Path to the MSI installer file.
# -LogPath: Path to a directory for installation log files.

param(
    [Parameter(Mandatory=$true)]
    [string]$MsiPath,

    [Parameter(Mandatory=$false)]
    [string]$LogPath
)

# --- SCRIPT LOGIC ---
if (-not (Test-Path -Path $MsiPath -PathType Leaf)) {
    Write-Host "Error: The specified MSI file was not found." -ForegroundColor Red
    exit
}

# Construct the full command for silent installation
# /i for installation, /qn for quiet mode (no user interface)
# /L*v for verbose logging
$msiArgs = "/i `"$MsiPath`" /qn"

# Add logging parameters if a log path is provided
if ($LogPath) {
    if (-not (Test-Path -Path $LogPath -PathType Container)) {
        New-Item -ItemType Directory -Path $LogPath | Out-Null
    }
    $logFile = Join-Path -Path $LogPath -ChildPath "msi_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
    $msiArgs += " /L*v `"$logFile`""
    Write-Host "Installation log will be saved to: $logFile" -ForegroundColor Yellow
}

Write-Host "Starting silent installation of $($MsiPath)..."

try {
    # Execute the MSI command
    $process = Start-Process -FilePath "msiexec.exe" -ArgumentList $msiArgs -Wait -PassThru
    
    # Check the exit code for success
    if ($process.ExitCode -eq 0) {
        Write-Host "Installation completed successfully." -ForegroundColor Green
    } else {
        Write-Host "Installation failed with exit code $($process.ExitCode)." -ForegroundColor Red
        Write-Host "Refer to the log file for details." -ForegroundColor Red
    }
} catch {
    Write-Host "An error occurred during the installation process: $($_.Exception.Message)" -ForegroundColor Red
}

Detailed Breakdown

FeatureDescription
Identifying the MSIThe script uses a mandatory parameter, $MsiPath, to receive the path to the installer file.
A Test-Path check ensures the script won't proceed if the file doesn't exist, preventing runtime errors.
This simple validation is a best practice for reliable scripts.
Silent Installation SwitchesThe core of the PowerShell silent deployment is the use of msiexec.exe, the native Windows Installer command-line tool.
The script uses the /qn switch, which stands for "quiet, no UI." This tells the installer to run in the background without any graphical interface.
For a comprehensive list of these switches, refer to
Microsoft Docs on msiexec command-line options.
Logging for TroubleshootingThe script includes an optional logging feature. When a -LogPath is provided, the script uses the /L*v switch
to create a verbose log file. This log is crucial for troubleshooting failed installations.
The script saves the log with a timestamp, making it easy to track individual deployment attempts.
Executing and Monitoring the ProcessThe Start-Process cmdlet is used to launch the msiexec process.
The -Wait parameter is critical; it forces the script to wait for the installer to finish before proceeding.
After the process completes, the script checks the $process.ExitCode property.
An exit code of 0 indicates a successful installation, while any other value signifies a failure,
making it easy to see if the deployment was successful.

Use Cases

  • New Employee Workstation Setup: When setting up a new computer, use this script to install a standard set of applications like a web browser, office suite and collaboration tools. This gives the end user a consistent and ready to use experience.

  • Mass Software Updates: This script can be used with a deployment tool or a Group Policy Object (GPO) to push software updates to hundreds or thousands of machines at once, a great script to deploy applications.

  • Automating Application Installs: IT teams can use this script to create a central repository of installers. When a user or system needs a specific application, the script can be triggered to install it silently and automatically without IT having to be present.

Conclusion

Deploying software with a PowerShell application deployment script is a game changer that saves hours and reduces the risk of human error. This script is a simple but powerful foundation that can be extended to handle more complex scenarios like deploying software with custom settings or different installer types (e.g. .exe installers). 

Deploy this script across your Endpoints with Zecurit

Upload this script to Zecurit's Script Repository and execute it across hundreds of endpoints in minutes. Support for PowerShell, Bash, Python,and more with full audit trails and scheduling.

Frequently Asked Questions (FAQs)

  • How do I find the correct silent switches for an MSI?

    The standard silent switches for MSI installers are /qn for no UI and /L*v for verbose logging. The msiexec.exe utility is standardized. For third-party or custom installers (e.g., .exe), the switches can vary. You can often find these by running the installer with /h or /? to display help, or by searching the vendor's documentation.

  • Does this script work for .exe installers?

    This script is specifically written for MSI installers, which use msiexec.exe. While you can adapt the Start-Process part of the script for .exe installers, the command-line arguments will be different and must be determined on a case-by-case basis. Some common switches for .exe installers are /s, /silent, or /quiet.

  • What permissions are needed to run this script?

    The script requires local administrator privileges on the machine to install software. This is a standard requirement for most software installations. If you are deploying the script via Group Policy, you must ensure it runs with an account that has elevated permissions.

  • How can I handle multiple applications?

    You can either run this script multiple times with a different $MsiPath parameter each time, or you can modify the script to read a list of MSI files from a text file or an array and iterate through them. This makes it a true script to deploy applications in bulk.