Check-AppsNotEnabledForTaskSequenceInstall.ps1

  • 6 February 2023
  • Sean Huggans
Description: 

Script will check through all existing ConfigMgr application packages and ensure that the option to "Allow this application to be installed from the Install Application task sequence action without being deployed" is enabled, and enable it if it is not.

The script can easily be configured to run on a scheduled task on a regular basis to prevent task sequence errors due to forgetting to set this manually. The script queries for applications via SQL vs. using the Get-CMApplication commandlette as it's much faster/less resource intensive.

Language: 
PowerShell
Usage Type: 
Standalone
Script Source: 
#####################################################
# Check-AppsNotEnabledForTaskSequenceInstall
# Script Author(s): Sean Huggans
$ScriptVersion = "23.2.6.1"
#####################################################
# Variables
##############################################
$global:SiteServer = "SITESERVER"
$global:SiteCode = "FOO"
$LogFile = "Check-AppsEnabledForTaskSequenceInstall.log"
$LogDir = "c:\Temp"
$LogPath = "$($LogDir)\$($LogFile)"
 
#####################################################
# Functions
##############################################
 
function Log-Action ($Message, $StampDateTime, $WriteHost)
{
    ################################
    # Function Version 19.5.11.4
    # Function by Sean Huggans
    ################################
	New-Item -ItemType directory -Path $LogDir -Confirm:$false -Force | out-null
    if (($StampDateTime -eq $false) -or ($StampDateTime -eq "no")) {
        $Message | Out-File $LogPath -Append
    } else {
	    "[ $(get-date -Format 'yyyy.MM.dd HH:mm:ss') ] $($Message)" | Out-File $LogPath -Append
    }
    if ($WriteHost -eq $true) {
        Write-Host $Message
    }
}
 
function Invoke-SQL
{
	param (
		[string]$dataSource = "$global:SiteServer",
		[string]$database = "CM_$global:SiteCode",
		[string]$sqlCommand = $(throw "Please specify a query.")
	)
 
	$connectionString = "Data Source=$dataSource; " +
	"Integrated Security=SSPI; " +
	"Initial Catalog=$database"
 
	$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
	$command = new-object system.data.sqlclient.sqlcommand($sqlCommand, $connection)
	$connection.Open()
 
	$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
	$dataset = New-Object System.Data.DataSet
	$adapter.Fill($dataSet) | Out-Null
 
	$connection.Close()
	$dataSet.Tables	
}
 
#####################################################
# Execution Logic
##############################################
Log-Action -message "-------- Beginning Check for Application Packages not enabled for task sequence installation..." -WriteHost $true
# Get application package digests
$AllAppPackages = Invoke-SQL -sqlCommand "select LatestApp.DisplayName, LatestApp.SDMPackageDigest from fn_ListLatestApplicationCIs(1033) LatestApp"
foreach ($AppPackage in $AllAppPackages) {
    # Check each app package for AutoInstall being true
    if ($AppPackage.SDMPackageDigest -like "*<AutoInstall>true</AutoInstall>*") {
        Log-Action -message " - Application ""$($AppPackage.DisplayName)"" was already enabled for task sequence installations, skipping." -WriteHost $true
    } else {
        Try {
            $AppPackage2 = Get-CMApplication -Name $AppPackage.DisplayName
            Set-CMApplication -Id $AppPackage2.CI_ID -AutoInstall $true
            Log-Action -message " - WARNING!  Application ""$($AppPackage.DisplayName)"" was not enabled for task sequence install without deployment, this was successfully corrected." -WriteHost $true
        } catch {
            Log-Action -message " - ERROR!  Application ""$($AppPackage.DisplayName)"" is not enabled for task sequence install without deployment, and there was an error attempting to correct it automatically." -WriteHost $true
        }
    }
}
Log-Action -message "Finished Check for Application Packages not enabled for task sequence installation." -WriteHost $true
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.