In this post I´m going to show you how to use one single Powershell script to install, configure and deploy any application with any OSD tool.
I´ve been working with the various Microsoft Deployment Toolkits for a very long time, and my Automation Framework is based upon the same. I consider myself a Batman doing most in batch scripts and also a bit unorganised in terms of structure.
After talking to friends and customers at Citrix Synergy I realised that I need some better logging, specially when applications are installed via MDT. In some customer environments a MDT Task Sequence completed successfully, but some applications where still not installed.
Was the path wrong? Did I do something wrong? Do I need to sit around and watch? How long did it take?
The final thing that put me into this big time wasting project (short term) was the desire to reuse the MDT Application folder as a Chocolatey repository. WIth that in mind I created following the Powershell script wrapper which is also Chocolatey ready, Let´s jump into it.
In my last post The World´s Fastest Home Lab you learned how I now can deploy VM´s in 3 minutes and 20 seconds. So instead of wasting weeks on this project I only spent a couple of days. If you plan to build or upgrade your home lab, buy yourself an Intel 750 SSD PCIe. The double price is worth every penny and it seems to drop every week.
The Powershell Wrapper:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# PowerShell Wrapper for MDT, Standalone and Chocolatey Installation - (C)2015 xenappblog.com # Example 1: Start-Process "XenDesktopServerSetup.exe" -ArgumentList $unattendedArgs -Wait -Passthru # Example 2 Powershell: Start-Process powershell.exe -ExecutionPolicy bypass -file $Destination # Example 3 EXE (Always use ' '): # $UnattendedArgs = '/qn' # (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode # Example 4 MSI (Always use " "): # $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" # (Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Setting Arguments" -Verbose $StartDTM = (Get-Date) $Vendor = "Misc" $Product = "CutePDF" $PackageName = "CuteWriter" $Version = "3.0" $InstallerType = "exe" $LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log" $LogApp = "${env:SystemRoot}" + "\Temp\$PackageName.log" $Destination = "${env:ChocoRepository}" + "\$Vendor\$Product\$Version\$packageName.$installerType" $UnattendedArgs = '/verysilent' Start-Transcript $LogPS CD $Version Write-Verbose "Starting Installation of $Vendor $Product $Version" -Verbose (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Customization" -Verbose Write-Verbose "Stop logging" -Verbose $EndDTM = (Get-Date) Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose Stop-Transcript |
Much better file structure as well. I´m placing small vendors in Misc since it makes no sense to fill up the root folder with unknown vendor names.
Quiet install command for MDT:
1 |
powershell.exe ExecutionPolicy Bypass .\Install.ps1 -force |
There´s 2 log files created per application installation. One for the PS Wrapper where you will discover any problems with UNC path, MSI error or success code and total run time. The second is the actual application installation log file. Be aware that the MSI log cannot contain spaces, therefore only $Packagename.
The cool thing about this script and the folder structure are that you only need to change the version number in the Powershell wrapper script to install a newer application version or roll back to an older version.
To create a NUPKG package just replace everything below the $Arguments with the Chocolatey logics:
1 2 3 4 5 6 7 8 9 |
try { Install-ChocolateyPackage $packageName $installerType $unattendedArgs $destination Write-ChocolateySuccess "$packageName" } catch { Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)" throw } |
Share your MDT Applications folder and create an Environment variable in Group Policy.
To learn more check out the post Getting Started with Chocolatey and Boxstarter and How to Install Chocolatey Packages Offline.
All these updates and much more will be part of the Automation Framework 3.0 release coming soon.