Functions to help with application detection in SCCM

function Set-AppDetectRegistryKey {
<#
.SYNOPSIS
This Function Records a Value in the registry that can be used for Application Detection in SCCM
.EXAMPLE
Set-AppDetectRegistryKey -AppName ‘Application’ -Value ‘1’

	This example creates a value for 'Application' in HKLM\SOFTWARE\PSADK\Application Detection with a value of '1'
.PARAMETER AppName
	Application Name
.PARAMETER Value
	Value of Registry Entry
#&gt;
Param(
    [parameter(Mandatory=$false)]
    [String]
    $AppDeployReg,
    [parameter(Mandatory=$true)]
    [String]
    $AppName,
    [parameter(Mandatory=$true)]
    [String]
    $Value

)
If ($PSBoundParameters['AppDeployReg']) {
    $AppDeployReg = $AppDeployReg        
}
else {
    $AppDeployReg = "HKLM:\Software\PSADK\Application Detection"        
}
If (!(Test-Path $AppDeployReg)) {
    New-Item $AppDeployReg -Force | Out-Null
    write-log "Created $AppDeployReg"
}
New-ItemProperty $AppDeployReg -Name $AppName -Value $Value -Force | Out-Null
Write-Log "Created $AppDeployReg\$AppName with a value of $Value"

}

function Remove-AppDetectRegistryKey {
<#
.SYNOPSIS
This Function Records a Value in the registry that can be used for Application Detection in SCCM
.EXAMPLE
Remove-AppDetectRegistryKey -AppName ‘Application’

	This example creates a value for 'Application' in HKLM\SOFTWARE\PSADK\Application Detection with a value of '1'
.PARAMETER AppName
	Application Name
.PARAMETER Value
	Value of Registry Entry
#&gt;
Param(
    [parameter(Mandatory=$false)]
    [String]
    $AppDeployReg,
    [parameter(Mandatory=$true)]
    [String]
    $AppName
)
If ($PSBoundParameters['AppDeployReg']) {
    $AppDeployReg = $AppDeployReg        
}
else {
    $AppDeployReg = "HKLM:\Software\PSADK\Application Detection"        
}
Remove-ItemProperty $AppDeployReg -Name $AppName -Force | Out-Null
Write-Log "Removed $AppDeployReg\$AppName"

}

Function Register-Installation {
<#
.SYNOPSIS
Saves state information about the installation in the registry of the target computer.
.DESCRIPTION
Saves state information about the installation in the registry of the target computer.
.EXAMPLE
Register-Installation
#>
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘IsInstalled’ -Value 1 -Type DWord
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptName’ -Value “$appName” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptVendor’ -Value “$appVendor” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptVersion’ -Value “$appVersion” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptArch’ -Value “$appArch” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptLanguage’ -Value “$appLang” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptRevision’ -Value “$appRevision” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptVersion’ -Value “$appScriptVersion” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptDate’ -Value “$appScriptDate” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘ScriptAuthor’ -Value “$appScriptAuthor” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘PSADKVersion’ -Value “$appDeployMainScriptVersion” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘InstallationDateTime’ -Value “$currentDateTime” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘InstallationTimeZone’ -Value “$currentTimeZoneBias” -Type String
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘InstallationSource’ -Value “$scriptParentPath” -Type String
$logFile = “{0}{1}” -f $logDirectory, $logName
Set-RegistryKey -Key “HKEY_LOCAL_MACHINE\SOFTWARE\PSADK\InstalledApps$appName” -Name ‘LogFile’ -Value “$logFile” -Type String

Hi Alan,

Thanks for sharing. I’m just starting out with this deploymenttoolkit as I was using a custom vbs wrapper.
This wrapper already had a function to log all app information to the registry so we could query this in ConfigMgr and standardise on our applications in ConfigMgr. This part was missing in the original PSADK.

Thx!