Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / PowerShell

Automate MSI Installer

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
17 Sep 2013CPOL3 min read 28.1K   269   11   6
This tool copies MSI installers from a distributed server and installs it on a VM Wrokstation

Introduction

I had to install my MSI installers on a day to day basis whenever a build was generated and do a smoke test on the installation. I was looking for some free tools that could solve my problem but couldn't find one. Prior to this, I had no idea about scripting or programming and thought of trying my hand at it. Initially, I started with Batch commands and PSTools but did not find the reliability, then again my quest for a good scripting tool started and finally ended with Windows PowerShell.

It's really amazing and a very good scripting language from Microsoft where you can automate whatever you do using UI.

Prerequisites for Utility

Setup

  1. Install Windows PowerShell 3.0 on VM Machine, download available here.
  2. Setting up PowerShell – Launch PowerShell as Administrator and run the below commands:
    • Set-ExecutionPolicy -ExecutionPolicy Unrestricted [I have used Unrestricted as had no option for my scripts to be signed by a trusted publisher, for best security one can use "Allsigned"]
    • Enable-PSRemoting –SkipNetworkProfileCheck –Force (Yes to All) [The Enable-PSRemoting command enables remoting in Windows PowerShell. By default, this creates network rules that allow remote access from private and domain networks. The command uses the SkipNetworkProfileCheck parameter to allow remote access from public networks in the same local subnet. The command uses the Force parameter to suppress confirmation messages.]
    • WINRM QC
  3. Disable Windows Updates [This is required as updates take hell of a lot of time and next code fails]
  4. Join the machine/computer to domain and the domain user to the Administrators Group
  5. Login to the machine with the domain user
  6. Enable AutoLogon in registry
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\NT\CurrentVersion\Winlogon 
    • AutoAdminLogon = 1
    • DefaultUsername = domain\user
    • DefaultPassword = password (Create new string value (REGSZ) for DefaultPassword)
  7. Take a snapshot

Requirements

  • Windows PowerShell 3.0

Supported Platforms

  • Windows 2012 Server, Windows 8, Windows 7 SP1 and Windows 2008 R2 Server SP1

Using the Code

Flow of the Tool

  1. Verifies the presence of MSI/MSPs in a given location (shared location)
  2. Reverts the VM Workstation to desired snapshot and Power ON the VM
  3. Adds/Joins the remote computer to Domain
  4. Copies the required stuff to the remote computer
  5. Installs MSI using msiexec.exe silently
  6. Sends an email with a good HTML report

Utility Explanation

  • Part 1: Core Script DailyBuildModule.psm1 consisting of the core functions used to build the tool
  • Part 2: A PowerShell script Trigger.ps1 to trigger the tool using the functions in Core Script File so that there is no need to make any changes to DailyBuildModule.psm1
  • Part 3: Config/Initializer script InstallConfig.ps1 which consists of required variables

Core Script “DailyBuildModule.psm1”: All the required functions for the tool are written in this script, and below is the brief description:

  1. The entry point of the script is to get the required details (variables) that are necessary to run the utility. This is done by the function “Set-Configuration” which reads the variables from script “InstalConfig.ps1
  2. Resume-SnapShot” and “Start-VM” are the functions which revert to the required snapshot of the VM Workstation and Power ONs the VM machine
  3. Join-Domain” function Joins/Adds the computer to Domain
  4. New-RemotePSSession” creates a new PSSession to the required machine which consists of all the required credentials which are read from “InstalConfig.ps1
  5. Copy-ResourceFiles” function is used to copy the required files from source to the destination (Remote Machine folder) where folder on a remote machine is created using “New-RemoteFolder
  6. Get-ProductRegKey” function is used to read a registry of the installed product.
  7. New-HTMLReport” function gets the system information, product information can be added to it and “Send-eMail” function sends an email
  8. Functions “Start-Log”,” Write-Log”,” Write-ErrorLog” and ”Complete-Log” create a beautiful log for the tool

Trigger.ps1 imports the DailyBuildModule.psm1 and the cmd-lets are used to trigger the tool.

InstallConfig.ps1 is the script in which the entire variable is assigned.

Note: Do not change any variable names in this file other than their values, however these variable values can be directly given in Trigger.ps1.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead OpenText Technologies
India India
I am working as Lead Engineer in OpenText Technologies India, a leader in ECM Domain.
I am into Administration and QA.
Good at MS Windows Servers, PowerShell and SQL Servers

Comments and Discussions

 
QuestionPrerequisites... Pin
dandy7218-Sep-13 5:24
dandy7218-Sep-13 5:24 
AnswerRe: Prerequisites... Pin
Durgesh Nakkani19-Sep-13 4:56
professionalDurgesh Nakkani19-Sep-13 4:56 
QuestionSource code. Pin
Valery Possoz12-Sep-13 1:30
professionalValery Possoz12-Sep-13 1:30 
AnswerRe: Source code. Pin
JohnLudlowReading12-Sep-13 4:16
JohnLudlowReading12-Sep-13 4:16 
GeneralRe: Source code. Pin
Valery Possoz12-Sep-13 4:40
professionalValery Possoz12-Sep-13 4:40 
GeneralRe: Source code. Pin
Durgesh Nakkani13-Sep-13 6:51
professionalDurgesh Nakkani13-Sep-13 6:51 
Unable to select the files, hence unable to download.
Would be possible to upload the code directly

Durgesh

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.