2 PowerShell Software Installation Examples
You can do this.

2 PowerShell Software Installation Examples

Hello to all SysAdmins, PowerShell users, and anyone who simply wishes to create simple, but useful code that will serve you, your systems, and your team well. Now, and in the future.

Below are some real-life examples of PowerShell scripts that I like to use for installing software (in this case, some prerequisites) on servers. Let's first break down the contents.


  • The "Write-Host" part is to simply give you some feedback on what is running by displaying the text on the PowerShell screen. This also gives you a good idea of how long each section will take to run as the text will stay displayed until the installation is completed and will then move onto the next item. Be careful to resist the temptation, however, of skipping the sleep code. More on that below.
  • The next commented lines are to list the name of the program, the download source, and the source of the command line switches. All of this information can be a lifesaver for future you or your teammates, so don't skip this. If you cannot find the command line installation switches from the vendor or searching online, try running the following: msiexec.exe /i <application>.msi /? Of course, use the actual name of your msi file. This will show a pop-up (hopefully) with the command lines associated with the application.
  • CD is simply to change the focus of the script to the directory where the installation file is located. Remember to always run applications locally on the targeted machine. Attempting to target files on a file share and execute them locally can be, well, problematic.
  • Adding in the Start-Sleep for 30 seconds is a simple way to make sure that each installation has time to wrap up what is needed and close the setup. Remember, systems will only let one installation run at a time, so if a setup is still lingering in the task manager, the next one cannot start.
  • Finally, the last Write-Host is a friendly reminder to reboot your system so that all installations have a chance to finalize.


Write-Host "Installing URL ReWrite Module v2.1" -ForegroundColor blue -BackgroundColor white
# URL ReWrite Module v2.1 - requires IIS 
#  Useful command to see if the service is running:  Get-Service W3SVC
#  Download Source:  https://www.iis.net/downloads/microsoft/url-rewrite
#  Command Source:   msiexec.exe /i rewrite_amd64_en-US.msi /?
cd ..\URL_ReWrite_Module_v2.1
msiexec.exe /i rewrite_amd64_en-US.msi /quiet /norestart /l* installLog.log
Start-Sleep -s 30

Write-Host "Installing PostgreSQL Admin v6.5x64" -ForegroundColor blue -BackgroundColor white
# PostgreSQL Admin
#  Download Source:  https://www.postgresql.org/ftp/pgadmin/pgadmin4/v6.5/windows/
#  Command Source:  https://silentinstallhq.com/pgadmin-silent-install-how-to-guide/
#  Command Source:  /ALLUSERS switch not documented on any website, but it works!
cd ..\PGAdmin_v6.5_X64
.\pgadmin4-6.5-x64.exe /VERYSILENT /NORESTART /ALLUSERS
Start-Sleep -s 30

Write-Host "REBOOT your server to complete installations before proceeding." -ForegroundColor red -BackgroundColor white        


Enjoy and feel free to comment or share. Also, be sure to use the scrollbar at the bottom of the code example. ; )

Great Article Ryan! Love it!

Like
Reply

To view or add a comment, sign in

More articles by Ryan Calhoun

Others also viewed

Explore content categories