PassiveInstall Sample Usage

Example Usages:

  • Let's say that you want to add an additional file to the install.  The proper way to do that in PowerShell requires that you test for the existence of each directory in the folder path of your intended destination and create the folder if not present before copying the file or the copy will fail.  The Copy-PassiveFile cmdlet lifts you of that burden.
  • Lets say that you want to install an msi, patch it with a msp, import a registry file, and run a cmd or powershell script, and finally extract a bunch of files from a zip archive.  With PassiveInstall, you just call the Install-PassiveFile cmdlet with each file.  If the command needed arguments, like "/qn", you add those to the line as well.  No need to remember the full syntax on how to call the command line to use each file type, PassiveInstall does the work for you!
  • Even better, when used in conjunction with the App-V Sequencer and our AppV_Manage tool, you can automatically generate improvement scripts to fix many of the common shortcomings of vendor installers based on an analysis of how it installed.

It is generally a good idea to create/adapt a template, like from the example below, and use it as the basis for all of your scripts.  In the example below, there is a main customization area marked off.  This is where application specific changes are made.  Other features of this example:

  • It logs activity to the location specified.
  • You can right click on the ps1 file and "Run with Powershell".  If the process is not elevated (needed for installing things generally), it will detect this and automatically restart the script with Run As Admin, causing the Credential/UAC prompt.
  • NGEN queue flushes are performed to ensure all .Net Framework compilations complete prior to the end of the script - important in repackaging operations.

Example Script:

Here is an example script used to install and configure Trimble SketchUp Viewer:

# PassiveInstall.ps1
#
# Copyright 2017 TMurgent Technologies, LLP
#
#
# PURPOSE:
#    Automates a custom installation of an application as either a passive or silent installation.
#    This script can be further modified to add registry settings or add dependencies.
##########################################################################################################################

#----------------------------------------------------------------------------------
# Standard coding starting here (DO NOT MODIFY)
# Get folder that this PS1 file is in so that we can find files correctly from relative references
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

# Bring in common utility code
Import-Module "C:\Program Files\WindowsPowerShell\Modules\PassiveInstall\PassiveInstall.dll"

#If here, we are (now) running as an admin!
#---------------------------------------------------------------------------------

#==================================================================================
#                    MAKE CUSTOMIZATIONS HERE
$AppName = 'Trimble_SketchupViewer'
$InstallerLogFolder = "c:\Users\Public\Documents\SequencedPackage"
$InstallerLogFile = $InstallerLogFolder+'\Log_'+$AppName+'_MainInstaller.txt'
$DoSilent = 0  #Set to 1 for silent instead of passive

function Run_CustomInstall
{   

Write-Information "Reading in original firewall rules"
$initialFirewallRules = Get-PassiveFirewallRules
Write-Information " "
if ($DoSilent -eq 1) { Install-PassiveInstallFile -Installer "$($executingScriptDirectory)\vcredist_14\vcredist_x64.exe" -Arguments '/q'-DoSilent Install-PassiveInstallFile -Installer "$($executingScriptDirectory)\SketchUpViewer2019-x64.msi" -Arguments '/qn DISABLEADVTSHORTCUTS=1' -DoSilent } else { Install-PassiveInstallFile -Installer "$($executingScriptDirectory)\vcredist_14\vcredist_x64.exe" -Arguments '/q' Install-PassiveInstallFile -Installer "$($executingScriptDirectory)\SketchUpViewer2019-x64.msi" -Arguments '/qn DISABLEADVTSHORTCUTS=1' } Copy-PassiveFile -Source "$($executingScriptDirectory)\PrivatePreferences.json" -Destination "$($env:LOCALAPPDATA)\SketchUp\SketchUp 2019\Sketchup" Remove-PassiveDesktopShortcuts -Names 'SketchUp Viewer.lnk'


# Check for new firewall rules and touch them from this process so that they are captured by the MMPT
Write-Information "Reading in updated firewall rules"
$updatedFirewallRules = Get-PassiveFirewallRules
Write-Information " "

$changedFirewallRules = Redo-PassiveNewFirewallRules $initialFirewallRules $updatedFirewallRules
Write-Information " "
$changedFirewallRules.Show()

if ($DoSilent -eq 1) { Optimize-PassiveNgenQueues -DoSilent } else { Optimize-PassiveNgenQueues } } # end of CUSTOMIZATION area #================================================================================= # Do NOT Modify below this line New-PassiveFolderIfNotPresent $InstallerLogFolder if ($DoSilent -eq 1) { Set-PassiveWinSize 10 7 5 5 -Title 'PowerShell - PassiveInstall.ps1' -DoSilent # Ensure we are running elevated Approve-PassiveElevation -AsAdmin } else { Set-PassiveWinSize 80 40 5 5 -Title "PowerShell - PassiveInstall.ps1 $($AppName)" Set-PassiveWinColors -Background 'DarkGray' -Foreground 'White' # Ensure we are running elevated Approve-PassiveElevation -AsAdmin Set-PassiveWinSize 100 44 10 10 -Title "[Elevated] PowerShell - PassiveInstall.ps1 $($AppName)" Set-PassiveWinColors -Background 'DarkGray' -Foreground 'White' Write-host 'Starting - PassiveInstall.ps1' } #If here, we are (now) running as an admin! #--------------------------------------------------------------------------------- $err = Run_CustomInstall *>&1 if ($DoSilent -ne 1) { Write-Output $err } Write-Output $err >> $InstallerLogFile #--------------------------------------------------------------- # Standard wrapup area (DO NOT MODIFY) write-host -ForegroundColor "Green" "Done." Show-PassiveTimer 20000 "End of script, P to pause for timer, when paused Q to quit the timer, any other key to resume." Start-Sleep 20 # end #---------------------------------------------------------------