04 April 2013

Powershell: Installation Script Functions

Posted By: Mick Pletcher - 1:11 PM


& Comment

Here are several snippets I have created for writing powershell application installation scripts. These make it a lot faster by standardizing the functions to use as reusable code.

Display a Balloon Tip
 Function BalloonTip($ApplicationName, $Message, $DisplayTime){  
      [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null  
      $balloon = New-Object System.Windows.Forms.NotifyIcon  
      $path = Get-Process -id $pid | Select-Object -ExpandProperty Path  
      $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)  
      $balloon.Icon = $icon  
      $balloon.BalloonTipIcon = 'Info'  
      $balloon.BalloonTipTitle = "{Company Name}"  
      $balloon.BalloonTipText = $ApplicationName+[char]13+[char]13+$Message  
      $balloon.Visible = $true  

Create a log folder and set log file
 $Global:LogFolderName = ""  
 Function CreateLogFolder{  
      If((Test-Path -path c:\temp) -ne $true){  
           New-Item -ItemType directory -Path c:\temp  
      If((Test-Path -path c:\temp\$Global:LogFolderName) -ne $true){  
           New-Item -ItemType directory -Path c:\temp\$Global:LogFolderName  
      $Global:LogFile = "c:\temp\"+$Global:LogFolderName+"\"+$Global:LogFolderName+".log"  
      Write-Host $Global:LogFile  

Enable/Disable File Security Checks
 #Disable File Security  
 #Enable File Security  

Determine if the OS is 32-bit or 64-bit
 Function GetOSArchitecture{  
      $Global:OS=Get-WMIObject win32_operatingsystem  
      #Answers: 32-bit, 64-bit  

Retrieve the relative path the powershell script was executed from
 Function GetRelativePath{  
      $Global:RelativePath=(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"  
      Write-Host $Global:RelativePath  

Uninstall previous versions of programs
 Function UninstallPreviousPrograms{  
      #Change '%application%' to whatever app you are calling  
      $Output = wmic product where "description like '%sketchup%'" get IdentifyingNumber  
      $Output | ForEach-Object {  
           $_ = $_.Trim()  
        if(($_ -ne "IdentifyingNumber")-and($_ -ne "")){  
          $GUID = $_  
      $Arguments = "/X"+[char]32+$GUID+[char]32+"/qb- /norestart"  
      (Start-Process -FilePath "msiexec.exe" -ArgumentList $Arguments -Wait -Passthru).ExitCode  

About Mick Pletcher

My blog is here to help solve issues I have encountered and solved, publish scripts I have written, and educate others in understanding areas that are not well covered


  1. Thanks! The disable file security checks was exactly what I needed to run a batch uninstall across my server farm. I'm not sure why, but the syntax below didn't work for me in my powershell script. Yours did!



Copyright © 2013 Mick's IT Blogs™ is a registered trademark.