ConfigMgr: How to deploy a MSU using PowerShell as the detection method
I have documented my approach on using PowerShell as a detection clause when deploying MSU files as it’s something that I have done many times but never blogged the process.
Here is the table I used as a reference that I stole from Technet that explained what I needed to do in the PowerShell code in order to signify a successful installation…simply write to the host! (stdout)
Table referenced here: https://technet.microsoft.com/en-gb/library/gg682159.aspx
So with that brief introduction out of the way, let’s do this step-by-step:
Start by creating a new application in the SCCM console:
For the installation program I use the following:
wusa.exe "File.msu" /quiet /norestart
And for the Uninstall program, (my screenshot below for the uninstall is slightly incorrect) I use this:
wusa.exe /uninstall "File.msu" /quiet /norestart
And here’s where the magic happens…(You can ‘Write-Host’ anything you like here, I used “Installed!” but as long as you write something to the stdout stream it will signify a successful detection.)
I’m not going to explain the PowerShell as it’s pretty obvious what’s going on…and yes…I know I can shorten all of this to one line but it’s more flexible and readable this way, so there!
You will obviously need to replace ‘KB40222720’, as in my example below, with the hotfix ID of the msu that you are deploying. To be sure of obtaining the correct HotfixID simply install the msu on a computer manually, and then in PowerShell run Get-Hotfix
which will list all of the installed hotfixes and their relevant HotfixID numbers:
Here’s the code to save you typing:
$UpdatesInstalled = Get-Hotfix 'KB40222720' -ErrorAction SilentlyContinue
If ($UpdatesInstalled) {
Write-Host "Installed"
}
Your requirements may differ from mine..
That’s all there is to it. Leave a comment below if this helped you out!
Get my books:
ConfigMgr - An Administrator’s Guide to Deploying Applications using PowerShell
“Understanding Microsoft Intune: Deploying Applications Using PowerShell” is available for purchase at all good book stores and online outlets. Don’t miss out on the opportunity to take your application deployment skills to the next level. Get your copy today!