Worklet: Install Slack on Windows

Installs Slack on Windows.

Evaluation code:

#REQUIRES -Version 2.0
<#
.SYNOPSIS
    This Test script checks to see if Slack is installed
.DESCRIPTION
    This script queries the installed files for 32 and 64bit software
    and returns a 0 if product is installed or 1 if not
.Notes
    File Name       :Slack_Install_Test.ps1
    Author          :Automox
    Prerequisite    :PowerShell V2 over win7 and upper
#>
#Handle Exit Codes:
trap {  $host.ui.WriteErrorLine($_.Exception); exit 90 }

function Slack_Install_Test {

	<#
    .SYNOPSIS
        This function Checks for the Slack is Installed on system or not .
    .DESCRIPTION
        After checking the Slack availability, based on the exit code tool will decide to call remediation code or not.
    .EXAMPLE
        Slack_Install_Test
    .NOTES
    #>

	# Name of the desired application.
	$appName = 'Slack'
	# Finding the Systen Directory (system32 Directory).
	$sysDir = [Environment]::SystemDirectory

	# Making the 32 bit and 64 bit path names blank.
	$32BIT = ""
	$64BIT = ""

	#Get Registry value for the 32 bit software installed on both 32-bit and 64-bit machine
	Try {  $32BIT = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction Stop |
			Select-Object DisplayName |
			Select-String "$appName" |
			Out-String
	}
	Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;
			Write-Output $Exception
			exit 90
	}
	# Script blcok to execute with powershell
	# Match name in the block should be hard coded.
	$scriptBlock = {$key = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' |
					Where-Object { $_.DisplayName -match 'Slack'}
					return $key
					}

	# Get the Registry value for the 64 bit software installed on the 64 bit machine. as the automox process is 32 bit
	if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")
	{
		# Call for accessing the 64 bit registry incase 32 bit process not access the registry.
		Try
		{
			$installed64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)
			$64BIT = $installed64.DisplayName
		}
		Catch
		{
			$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;
			Write-Output $Exception
			exit 90
		}

	}
	# Check for the Availability of the software and exit with relevent exit code.
	if ($32BIT.Trim() -match $appName -or ($64BIT -ne $null -and $64BIT.Trim() -match $appName)) {
		#Application Found, Automox can handle the updates!
		exit 0
	} else {
		# Application is not installed! Run Remediation Script to install it.
		exit 1
	}
}

Slack_Install_Test

Remediation code:

#REQUIRES -Version 2.0
<#
.SYNOPSIS
    This script allows an admin to install Slack
.DESCRIPTION
    This script downloads the system-wide-slack installer. Once installed, the program
    checks to see if slack is installed WHEN A USER LOGS IN. If slack is not installed
    the program installs it in the packground.
    If a user has uninstalled slack, this will not reinstall it.
.NOTES
    File Name       :Slack_Install.ps1
    Author          :Automox
    Prerequisite    :PowerShell V2 over win7 and upper
#>
#Handle Exit Codes:
trap {  $host.ui.WriteErrorLine($_.Exception); exit 90 }

function Slack_Install{

    <#
    .SYNOPSIS
        This function allows automox to Install the Slack on Windows .
    .DESCRIPTION
        This function download and installs the latest version of Slack on system.
    .EXAMPLE
        Slack_Install
    .NOTES
    #>

    #############Change the settings in this block#######################
    # Save the installer in the powershell current working directory.
    $saveFilePath = "$PSScriptRoot\SlackSetup.msi"
	
	# If any old installer file is existed, Delete the old installer.
    if (Test-Path -Path "$saveFilePath") {
		Remove-Item -force "$saveFilePath" -ErrorAction SilentlyContinue
    }

    # Download msi Installer based on the bit version of the Windows OS
    if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit") {
        $URL = "http://slack.com/ssb/download-win64-msi"
    } else  {
        $URL = "http://slack.com/ssb/download-win-msi"
    }

    ###### Download the msi installer file for the installation ######
    $downloader = (new-object System.Net.WebClient)
    Try {
        $downloader.DownloadFile("$URL", "$saveFilePath")
        Write-Output "Slack Installer download finished..."
    }
    Catch { Write-Output "File download failed. Check URL [$URL] and try again."
            exit 90
    }

    ###### Installing  slack on system ######
    Try {
        $process=Start-Process -FilePath msiexec.exe -ArgumentList '/i',$saveFilePath,'/q' -Wait -PassThru -ErrorAction Stop
        Write-Output "Slack Installion Finished..."
    }
    Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber
            Write-Output $Exception
            exit 90
    }

    # Avoid error while deleting the installer as it is still in the process of installation.
    do {
        if ((Get-Content $saveFilePath)) {
            Write-Output "Installer complete...cleaning up installation files"
            Remove-Item -force "$saveFilePath" -ErrorAction SilentlyContinue
            exit $process.ExitCode
        } else {
            Write-Output "Waiting for Installer File Unlock"
        }
        $fileunlocked = 1
    }	Until ($fileunlocked)

}

Slack_Install
1 Like

Would you do a version for Zoom?

https://www.zoom.us/client/latest/ZoomInstallerFull.msi

1 Like

You should actually be able to do that with a required software policy. That will check to make sure Zoom is installed and install it if it is missing. If that won’t work for you let me know and I can look into making a worklet version instead.

1 Like

Thanks Nic!

In case you haven’t done a required software policy before, you just need the installer, and then the name and version number that shows up in Add/Remove programs once it’s installed. Once you have those, put them in the required software policy and it checks against the Add/Remove programs DB automatically, and then runs the installer command if it is missing. We now updated Zoom as a 3rd party app, so you don’t need to make sure that they’re on the latest version. Here’s the KB with all the details and screenshots:


If you run into any problems let me know and I or support can help you out.

2 Likes

It didn’t seem to work. What would the installation command look like if this is what it normally looks like?

msiexec /i ZoomInstallerFull.msi /quiet /qn /norestart /log install.log

1 Like

Yep you can just put that command with all the flags into the installer window. Note that you have to click on the icon in the upper right to edit that installer window (the other code blocks don’t have that, so I mention it because I always forget and try to paste in there without clicking the button first, and then start wondering why my copy paste isn’t working).

This thread also has some details on getting it to work. It’s for a specific use case and might be more detail than you need, but I’m linking it in case it helps: