Wednesday, November 4, 2015

Java 8 Deployment with SCCM 2012 and PowerShell App Deployment Toolkit

OVERVIEW

This is an updated version of my original Java post from last year. This applies to Java 8 only. Oracle has made some slight changes to Java 8, but the package itself is nearly the same.


PowerShell App Deployment Toolkit

If you don't know about it, there's a nice little bundle of PowerShell scripts and configuration files that give you tons of options that can be useful. It's called the PowerShell App Deployment Toolkit.

https://psappdeploytoolkit.codeplex.com/

A couple of people put this together and it's a perfect toolkit to use if you are trying to deploy software where certain applications must be closed before they can install. They include a very easy guide to follow and get you started. Do not be daunted that this is all PowerShell based, especially if you don't know or feel comfortable with PowerShell. It's pretty simple to use and example scripts/scenarios are provided. The bonus is that you don't have to rely on a deployment tool such as SCCM. It can be run as a stand-alone package.

This has worked on Windows XP on up without having to upgrade PowerShell on XP systems, but it's something to consider if Windows XP is still in your environment. The highest version XP supports is PowerShell 2.0.

Review the App Deployment Toolkit documentation. Pay special attention to the examples provided. You can adjust some of the default behaviors set in the .XML files. In my environment, I modify the AppDeployToolkitConfig.xml file in the AppDeployToolkit folder and change the default path for the logs (<Toolkit_LogPath> and <MSI_LogPath>).


Build the Package

I create a folder for the package. In this case, the root folder is called 8Update65. Following the user App Deployment Toolkit guide, I copied the folder structure from the App Deployment Toolkit within the 8Update65 folder:



          NOTE: The Config folder is NOT part of the Application Deployment Toolkit. It can be ignored.

I then downloaded the latest Java version to a temp folder on my test machine. While you can use the .EXE file as it is, it's a little bit easier, in my opinion, to extract and use the .MSI file. To do that, start the install, but don't do anything beyond the Welcome screen. Once at the Welcome screen, open up Windows Explorer (My Computer) and browse to:

C:\Users\[UserName]\AppData\LocalLow\Sun\Java\[Java_Version] (where [UserName] is your user name and [Java_Version] is the version that was downloaded)

There will be one file...the .MSI. Copy it into the Files folder as shown from the screenshot above, then cancel out of the Java install.

Go to the 8Update65 folder, right mouse click the Deploy-Application.ps1 file and choose Edit. PowerShell ISE should launch. Enter the relevant information in the # Variables: Application section. Some of the information is shown in the dialog boxes during the deployment.




Again, using the guide, determine the tasks and setting you want to do for each section (PRE-INSTALLATION, INSTALLATION, POST-INSTALLATION, and UNINSTALLATION). For this example, I'm doing the following:

PRE-INSTALLATION:

This is not going to be a silent deployment because user interaction is required. I set:

Show-InstallationProgress

I want to check to see if any browsers are running, and if they are, prompt the user to close them. I set:

Show-InstallationWelcome -CloseApps "iexplore,firefox,chrome,safari,opera" -PersistPrompt

Using the -PersistPrompt switch will make the dialog box re-appear every minute until the browsers are closed.






INSTALLATION:

This is where you set your command line for the install. Most vendors will have documentation on what switches and parameters are available.
To make the client aware of the installation progress, I set:
Show-InstallationProgress and add what I want the message box to say. Below that is the Execute-MSI command needed. Notice that I use the silent install switch "/qn". The client will see the PowerShell dialog box, NOT the Windows Installer progress bar.
For this particular package, I do not want the previous Java versions overwritten, so I also have the STATIC=1 parameter (screenshot doesn't match - use the command below the screenshot).



Execute-MSI -Action Install -Path "jre1.8.0_65.msi" -Parameters "STATIC=1 AUTUPDATECHECK=0 ALLUSERS=1 DWUSINTERVAL=120 JAVAUPDATE=0 AUTO_UPDATE=0 WEB_JAVA=1 WEB_JAVA_SECURITY_LEVEL=H WEB_ANALYTICS=0 EULA=0 REBOOT=0 SPONSORS=0 /qn"

No steps were configured in the POST-INSTALLATION section.

UNINSTALLATION

I again want to check if any browsers are running before the removal. In this case, because it is being removed most likely by choice, I set the parameter, -CloseAppsCountdown to kill the browsers after 2 minutes if the client isn't there to do or ignores the dialog box. I then go on to set the uninstall command line switches.




Note that the path is the Product ID for this particular version of Java. The Product ID will be DIFFERENT if another version of Java is being packaged. To determine the Product ID, you can install manually on a test machine, then go into the test machine registry:


Determine Product ID for other versions of Java

32-bit Systems:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

64-bit Systems:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Do a search for Java in the Uninstall folder and a subfolder should quickly be found. This folder name is the Product ID you need for the uninstall command.

Create SCCM 2012 Application

Fire up the SCCM Console and click on Software Library in the lower left corner.




Expand Application Management. Right mouse click Applications and choose Create Application





Even though there is an .MSI, we are going to use the Deploy-Application.EXE from the App Deployment Toolkit, so choose to Manually specify the application information and click Next.




In the General Information window, set the Name, Publisher, and Software version. If you want to use this in an SCCM Task Sequence, make sure the "Allow this application to be installed from the Install Application task sequence action without being deploy" option is checked. Setting the Owner and Support Contacts is optional. Click Next when done.




Setting the Application Catalog options will depend on your environment and if you are using a company portal or not. Click Next.




The Deployment Type is where we specify the package location and command line to install. Click the Add... button.



Change type to Script Installer in the drop down menu (it defaults to Windows Installer *.msi file). Changing the type will automatically select the Manually specify the deployment type information option. Click Next.



You can use the same name as before or simply call it "Install". I chose Java 8 Update 65 - Install. No language settings are necessary. Click Next.



Browse to the location of the 8Update65 folder, then set the commands for Installation and Uninstall. I also select the "Run installation and install program as 32-bit process on 64-bit clients" because this is a 32-bit package.



We now need to add a detection rule so SCCM can confirm if the install completed successfully. Because we are using the .MSI, we can use the Product ID as the detection method. Click Add Clause...



Change the Setting Type: to Windows Installer in the drop down list. Click Browser and point to the .MSI in the Files folder under 8Update65 and click OK. The Product code: field will automatically be populated. In most cases, this will be enough, however, if clients may have a newer version already installed, this version won't be necessary. Change the rule so the version is greater than or equal to the version being deployed. This will make it so only clients with 8 Update 64 or older will get the install. Anything newer will show as Already Compliant. Click OK, then click Next.



Because we need user interaction, we want to make sure the dialog boxes appear. Therefore, it must only install when a user is logged in. This is not a profile specific application, so we can choose to Install for system (uses the SYSTEM account priviledges) as the Install behavior. Logon requirement MUST BE set to Only when a user is logged on. Installation program visibility MUST BE set to Normal. "Allow users to view and interact with the program" MUST BE checked. Setting the Maximum allowed run time and Estimated installation time is optional but good practice.



Requirements are optional. You can set things like required disk space or OS versions if you choose.



There are no prerequisites needed for Java to install, so simply click Next.



The Summary will let you review your settings. Click Next to complete the build of the Application.

Before distributing content and deploying to collections, I test the install (copy the 8Update65 folder to a test machine) as a stand-alone (double-click Deploy-Application.EXE) and confirm it works as expected. Tweak settings as needed in the Deploy-Application.ps1 file and repeat testing. When satisfied with the results, remember to copy any changes back to your network source location of the package before distributing.

Once validated as a stand-alone install, you should be ready to distribute content and test the deployment to a test or pilot collection of systems.

Good luck!

Uninstall Strings

Overview


As a software packager/patch manager, knowing how to uninstall software, and often, silently can be a nightmare. Most vendors will typically have an "Uninstall String" in the registry. This is the command used when you go to Programs and Features and click Uninstall, but those are not silent. You have to click through the uninstall wizard until it shows it is finished.

If the software was packaged as a Windows Installer package (.MSI), then adding silent switches is very simple because you use the default Windows Installer switches (typically /qn). Other packaging methods, unless the vendor has documented, it can be a guessing game (/s vs. /silent or /q vs. /quiet /u vs. /uninstall) and even then, a silent option may not even exist.

Because most software vendors create the Uninstall String in the registry, I can utilize SCCM 2012 to include this key in the Hardware Inventory (yes, Hardware, not Software). Older versions of SCCM require modification of a .MOF file, but 2012, you can add it from an existing machine. I will not go into the details of modifying the .MOF file as there are other articles out there that cover this.

For this blog, I'll be documenting the method of modifying the Hardware Inventory for SCCM 2012, then creating an SCCM (SSRS) Report where you can type in the name of the product and see if an Uninstall String exists and show that string the in the report.


Modify the Hardware Inventory - SCCM 2012


Depending on your company's configuration, you will want to modify the Client Settings that include Hardware Inventory. This is usually done with "Default Client Settings", but your environment may have several different setting profiles. Choose the one that is appropriate for your environment if Default Client Settings is not used.

In the System Center 2012 Configuration Manager Console (connected to your CAS, not a Primary), do the following:

01.  Click on Administration
02.  Click on Client Settings
03.  Right mouse click "Default Client Settings" and choose Properties


04.  Select Hardware Inventory, the click Set Classes...



05.  Scroll down to Installed Applications (64) (Win32Reg_AddRemovePrograms64) or Installed Applications (Win32Reg_AddRemovePrograms)
06.  If you do not see one or the other, they will need to be added. Skip to Step 08 below. Otherwise, expand both and make sure UninstallString is checked.




07.  If it is already checked, then you are already collecting the inventory and can move on to creating the report. Otherwise, check the box(es) and click OK.

Depending on how often you have Hardware Inventory scheduled to run, it can take a few days to get a good amount of data. Force a Hardware Inventory to run on a few machines to verify the data is being collected and create the report.

08.  To add Installed Applications (64) (Win32Reg_AddRemovePrograms64) or Installed Applications (Win32Reg_AddRemovePrograms), click the Add... button.

09.  Click the Connect... button and enter a machine name and credentials with admin rights (not needed if pulling from the machine running the console). Make sure the Recursive box is checked, then click Connect. This may take a minute or two to load.




10.  In the Search box, type Reg_Add. You should see Win32Reg_AddRemovePrograms and Win32Reg_AddRemovePrograms64. Check both of them and make sure the entire class is checked.



11.  Click OK, then click OK two more times to exit out of all windows.

Depending on how often you have Hardware Inventory scheduled to run, it can take a few days to get a good amount of data. Force a Hardware Inventory to run on a few machines to verify the data is being collected and create the report.

Create the Reports


SCCM 2012 uses SSRS for report creation. Go to your SSRS server for Configuration Manager and create a new report wherever appropriate in your environment. Below are the queries for 32-Bit and 64-Bit applications.

Use the following query for 32-Bit Applications:

SELECT DISTINCT v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 as 'Software Name' ,v_GS_ADD_REMOVE_PROGRAMS.Version0 as 'Software Version' ,v_GS_ADD_REMOVE_PROGRAMS.UninstallString0 as 'Uninstall String'
FROM v_GS_ADD_REMOVE_PROGRAMSWHERE v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 LIKE @SoftwareName

Use the following query for 64-Bit Applications:

SELECT DISTINCTv_GS_ADD_REMOVE_PROGRAMS_64.DisplayName0 as 'Software Name',v_GS_ADD_REMOVE_PROGRAMS_64.Version0 as 'Software Version',v_GS_ADD_REMOVE_PROGRAMS_64.UninstallString0 as 'Uninstall String'FROMv_GS_ADD_REMOVE_PROGRAMS_64WHEREv_GS_ADD_REMOVE_PROGRAMS_64.DisplayName0 LIKE @SoftwareName

The 32-Bit report is likely the one that will be used the most because a majority of applications are installed as 32-Bit by default or do not have a 64-Bit version. For the @SoftwareName parameter, I set a default value of %notepad++%. This is not required, however, I set it so users that have access to the report understand the format of the search to use. The % signs are required because we are using LIKE in the query. If "=" was used, the exact name of the software would be needed instead.

Run the report to verify it is pulling data. If no data is found, make sure at least one machine has done a Hardware Inventory and try it again. Also make sure you are searching for software you know is installed on the machine. It may take a few minutes for machines to report the data and SCCM to process it so it shows in the report. As more machines report in, the report will continue to grow as well.

The results will show the Uninstall String value for every version of the software found. I export to .CSV and filter out the duplicates and use that in my package/script for uninstalls.