ConfigMgr Lab – Adding Ninite Apps

So you have a Personal ConfigMgr lab, but you want to add some app deployments to better simulate your actual environment.  So you add Chrome, Reader, and a couple others (NOT JAVA).  Next Month, they are out of date.  You probably don’t have time to keep your personal lab app deployments updated, so you keep deploying old versions.  How about, you leverage ninite.com’s ability to dynamically install the latest version of the app every time?  Now you’re asking, “Isn’t the command line version that supports silent install cost money?”  Yes, yes, it does, to use ninite’s silent install, you need the Pro version.  What, you don’t want to pay for pro when it’s your personal lab?  I hear you.  Powershell to the rescue!  It doesn’t make it completely silent, but it will allow you to automate it to work with the ConfigMgr App Model during OSD and Post OSD.

If you’re not familiar with Ninite.com, it’s pretty awesome.  I’ve been using it for years, when I get a new computer, or just want to make sure my apps are updated.  Also use it to help setup how many friend’s and family’s computers. Basically, you go to the website, you check the box next to the app(s) you want, and click “Get your Ninite”.  Then run the small stub installer file.  Awesome right?  They figured out all of the command lines. They keep the apps updated. They make it so easy.

Please remember, this is for your personal lab, if it is for anything other than personal use, you’d have to get the Pro version.  With the Pro version, you don’t need my work around.

Basically my solution is a powershell wrapper that downloads the ninite stub installer,  runs the installer, waits for it to finish, then kills the installer dialog box.  Why would you want to do this?  Automation, being able to leverage Ninite’s Free Personal installers in the context of a Task Sequence or App Model deployment in your Personal ConfigMgr Home Lab.

The Script does this:

  1. You choose the App you want to install from the predefined list built into the script
  2. The script then Downloads the Ninite.exe stub file from Ninite.com
  3. Then launches the Ninite Installer.exe stub file which downloads the actual app installer and launches
  4. Waits for either MSIEXEC.EXE or TARGET.EXE Subprocess of Ninite.exe to start.
  5. Monitors the SubProcess (MSIEXEC.EXE or TARGET.EXE)
  6. Once SubProcess (software install) completes and goes away, Sends “Stop-Process” signal to stop all Ninite.EXE processes
  7. Deletes the file it downloaded
  8. DONE.

In Software Center (Application Model Deployment).  It will Launch the installer, the ninite dialog box will be visible until it is complete. (See video below for demo

image

In the TS, you can add the Applications like any other.  During at TS, the installers are not visible. (See video below for demo)

image

Content: One PowerShell Script

Same Command Line Install for each, just change it to match the software.

powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp 7Zip -Invoke Install
powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp 7Zip -Invoke Uninstall

Detection Method (File Only) – I don’t use version number, as it’s constantly changing.  If you want to rerun the app, uninstall it first, then rerun to get the updated version.  However, assuming this was a lab, I made the assumption the machines you’re installing apps on, probably won’t “live” for long before blown away or reloaded.
image

PS Code

#Ninite Installer Script
#Downloads Ninite Installer based on Input
#Currently Supports a few different apps, feel free to add others
#Supports Install & Uninstall

[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,Position=1,HelpMessage="Application")]
[ValidateNotNullOrEmpty()]
[ValidateSet("7Zip", "Chrome", "FileZilla", "Firefox", "GreenShot", "VLC", "VSCode", "WinDirStat")]
[string]$NiniteApp,
 
    [Parameter(Mandatory=$true,Position=2,HelpMessage="Install or Uninstall")]
[ValidateNotNullOrEmpty()]
[ValidateSet("Install", "Uninstall")]
[string]$Invoke
)

Write-Host $NiniteApp
Write-Host $Invoke

#Timeout if things are taking too long, odds are good something was too quick for process to monitor, so this is here to make sure it doesn't hang.  15 Minute Timeout, unless the app specifies otherwise.
$AppTimeout = "901"

#Set Information Per App to be used laster
#Download & Process Info

if ($NiniteApp -eq "7Zip")
{
$downloadlink = "https://ninite.com/7Zip/ninite.exe"
$uninstallstring = '"C:\Program Files\7-Zip\Uninstall.exe" /S'
$AppTimeout = "300"
}
if ($NiniteApp -eq "Chrome")
{
$downloadlink = "https://ninite.com/chrome/ninite.exe"
$uninstallstring = "wmic product where name=""Google Chrome"" call uninstall"
}
if ($NiniteApp -eq "FileZilla")
{
$downloadlink = "https://ninite.com/FileZilla/ninite.exe"
$uninstallstring = '"C:\Program Files\FileZilla FTP Client\uninstall.exe" /S'
$AppTimeout = "300"
}
if ($NiniteApp -eq "Firefox")
{
$downloadlink = "https://ninite.com/FireFox/ninite.exe"
$uninstallstring = '"C:\Program Files\Mozilla Firefox\uninstall\helper.exe" /S'
}
if ($NiniteApp -eq "GreenShot")
{
$downloadlink = "https://ninite.com/GreenShot/ninite.exe"
$uninstallstring = '"c:\windows\system32\taskkill.exe" /IM greenshot* /F & "C:\Program Files\Greenshot\unins000.exe" /SILENT'
}
if ($NiniteApp -eq "VLC")
{
$downloadlink = "https://ninite.com/VLC/ninite.exe"
$uninstallstring = '"C:\Program Files\VideoLAN\VLC\uninstall.exe" /S /NCRC'
}
if ($NiniteApp -eq "VSCode")
{
$downloadlink = "https://ninite.com/VSCode/ninite.exe"
$uninstallstring = '"C:\Program Files\Microsoft VS Code\unins000.exe" /SILENT'
}
if ($NiniteApp -eq "WinDirStat")
{
$downloadlink = "https://ninite.com/WinDirStat/ninite.exe"
$uninstallstring = '"C:\Program Files (x86)\WinDirStat\Uninstall.exe" /S'
$AppTimeout = "300"
}

if ($Invoke -eq "Install")
{
#Download the Ninite File
Invoke-WebRequest -Uri $downloadlink -OutFile $PSScriptRoot\NiniteInstaller.exe -UseBasicParsing -Verbose

if (!(test-path $PSScriptRoot\NiniteInstaller.exe))
{
Write-Host "Did not download, Exit Script"
exit
}

#Launch the Ninite Installer

start-process -FilePath "$PSScriptRoot\NiniteInstaller.exe"
$Y = 1
While(!(Get-WmiObject win32_process -Filter {Name =  'Ninite.exe'}) -and $Y -lt 10){
    Write-Output "Waiting for ninite.exe to download and launch"
    Start-Sleep -Seconds 1
    $Y++
}
#If internet connection not working right, it might not download 
If ($Y -ge 10)
{
Write-Host "Did not download, Exit Script"
Get-Process | Where {$_.Name -like "ninite*"} | Stop-Process -Verbose
exit
}

#Monitor Install Process

    $PIDs = (Get-WmiObject win32_process -Filter {Name = 'Ninite.exe'}).ProcessID
    Write-Host "Ninite Process IDs" $PIDs

    $MSIRunning = (Get-WmiObject win32_process -Filter {Name = "msiexec.exe" or Name = "Target.exe"} | Where-Object {$PIDs -contains $Psitem.ParentProcessID}).ProcessID 
    $X = 1
    while  ($MSIRunning -eq $null -and $X -lt "$AppTimeout")
    {
        $X++
        start-sleep -Seconds 1
        Write-Host "Waiting for Software Installer to Start"
        $MSIRunning = (Get-WmiObject win32_process -Filter {Name = "msiexec.exe" or Name = "Target.exe"} | Where-Object {$PIDs -contains $Psitem.ParentProcessID}).ProcessID 
    }
    Write-Host "Installer Started"
    Write-Host "Waiting for Software Installer To Finish"
    $ParentPID = (Get-WmiObject win32_process -Filter {Name = "msiexec.exe" or Name = "Target.exe"} | Where-Object {$PIDs -contains $Psitem.ParentProcessID}).ProcessID
    $ParentProc = Get-Process -Id $ParentPID
    $ParentProc.WaitForExit()
    Write-Host "Software Install Finished" 


#Kill Task on the Ninite Installer
start-sleep -Seconds 5
Write-Host "Kill Ninite Wrapper"
Get-Process | Where {$_.Name -like "ninite*"} | Stop-Process -Verbose

}
if (test-path $PSScriptRoot\NiniteInstaller.exe)
{
start-sleep -Seconds 2
Write-Host "Delete Ninite Installer"
Remove-Item "$PSScriptRoot\NiniteInstaller.exe"
}

#Run the Uninstall if in Uninstall Mode
if ($Invoke -eq "Uninstall")
{cmd.exe /c $uninstallstring}

Readme.txt

Install Command
powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp APPNAME -Invoke Install
Ex: powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp 7zip -Invoke Install

Uninstall Command
powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp APPNAME -Invoke Uninstall
Ex: powershell.exe -executionpolicy bypass -file "NiniteInstall.ps1" -NiniteApp 7zip -Invoke Uninstall

Detection Methods
7Zip: C:\Program Files\7-Zip\7z.exe
Chrome: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
FileZilla: C:\Program Files\FileZilla FTP Client\filezilla.exe
Firefox: C:\Program Files\Mozilla Firefox\firefox.exe
Greenshot: C:\Program Files\Greenshot\Greenshot.exe
VSCode: C:\Program Files\Microsoft VS Code\Code.exe
VLC: C:\Program Files\VideoLAN\VLC\vlc.exe
WinDirStat: C:\Program Files (x86)\WinDirStat\windirstat.exe

 

See it in Action

Video (Task Sequence)

Video (Software Center)

Watch the Script in Action:

Notes: PERSONAL LAB ONLY!
If you’d like to add other Ninite App options into the script, feel free.  I’ve found not all of them use the target.exe or msiexec.exe sub processes, so you’d have to account for that (Examples are .Net 4.7.1 and Paint.Net, for my lab, I pulled those out and made separate app scripts).

More info: Ninite.com Terms: “The free version of Ninite is only licensed for home use and as a trial for Ninite Pro. If you get paid for running Ninite (like in an IT department, PC shop, managed service provider, school, non-volunteer helpdesk, etc.) you must upgrade to Ninite Pro. ”

 

5 thoughts on “ConfigMgr Lab – Adding Ninite Apps”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.