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
- Install Windows PowerShell 3.0 on VM Machine, download available here.
- 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
- Disable Windows Updates [This is required as updates take hell of a lot of time and next code fails]
- Join the machine/computer to domain and the domain user to the Administrators Group
- Login to the machine with the domain user
- 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)
- Take a snapshot
Requirements
Supported Platforms
- Windows 2012 Server, Windows 8, Windows 7 SP1 and Windows 2008 R2 Server SP1
Using the Code
Flow of the Tool
- Verifies the presence of MSI/MSPs in a given location (shared location)
- Reverts the VM Workstation to desired snapshot and Power ON the VM
- Adds/Joins the remote computer to Domain
- Copies the required stuff to the remote computer
- Installs MSI using msiexec.exe silently
- 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:
- 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” - “
Resume-SnapShot
” and “Start-VM
” are the functions which revert to the required snapshot of the VM Workstation and Power ONs the VM machine - “
Join-Domain
” function Joins/Adds the computer to Domain - “
New-RemotePSSession
” creates a new PSSession
to the required machine which consists of all the required credentials which are read from “InstalConfig.ps1” - “
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
” - “
Get-ProductRegKey
” function is used to read a registry of the installed product. - “
New-HTMLReport
” function gets the system information, product information can be added to it and “Send-eMail
” function sends an email - 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.