This project is read-only.

New-ProgramEntry / Remove-ProgramEntry

Topics: Archive - Toolkit Extensions
Aug 25, 2014 at 3:28 PM
We have several applications in our environment that are "homegrown" and are not easily inventoried by SCCM. I have created this function and put it in the AppDeployToolkitExtensions file, but thought I would share it with you guys to see if you find it as a useful addition to the toolkit. I am sure that I am not the only admin/packager that has applications like these.

The function below creates a new entry in Programs and Features (Add/Remove Programs)
Function New-ProgramEntry{
<#
.SYNOPSIS
    Creates a new entry in Programs and Features (Add/Remove Programs)
.DESCRIPTION
    This function creates a new key in the 32-bit registry. Useful when you have a custom packaged application
    that you want to be inventoried by SCCM.
.EXAMPLE
    New-ProgramEntry -DisplayIcon "C:\MyApp\MyApp.ico" -DisplayName "My Awesome App" -DisplayVersion "1.0.0.0" -Publisher "Me" -UninstallString "C:\MyApp\Uninstall.exe"
.PARAMETER DisplayIcon
    The location of the icon to be displayed with the new entry
.PARAMETER DisplayName
    The name of the new entry
.PARAMETER DisplayVersion
    The version of the application
.PARAMETER Publisher
    The publisher of the application
.PARAMETER UninstallString
    The command that will uninstall this program
.PARAMETER CanModify
    Enables or Disables the Modify button in Programs and Features
.PARAMETER CanRemove
    Enables or Disables the Remove button in Programs and Features
.NOTES
#>
param(
    [Parameter(Mandatory = $true)]
    [string] $DisplayIcon,
    [Parameter(Mandatory = $true)]
    [string] $DisplayName,
    [Parameter(Mandatory = $true)]
    [string] $DisplayVersion,
    [Parameter(Mandatory = $true)]
    [string] $Publisher,
    [Parameter(Mandatory = $true)]
    [string] $UninstallString,
    [switch] $CanModify = $false,
    [switch] $CanRemove = $false
)

If($is64Bit){
    $UninstallPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
}Else{
    $UninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
}

If(!(Test-Path "$UninstallPath\$DisplayName")){
    New-Item -Path "$UninstallPath\$DisplayName"
}

New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name DisplayIcon -Value $DisplayIcon -PropertyType String -Force
New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name DisplayName -Value $DisplayName -PropertyType String -Force
New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name DisplayVersion -Value $DisplayVersion -PropertyType String -Force
New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name InstallDate -Value $(Get-Date -Format yyyyMMdd) -PropertyType String -Force
New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name Publisher -Value $Publisher -PropertyType String -Force
New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name UninstallString -Value $UninstallString -PropertyType String -Force
If($CanModify -eq $false){
    New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name NoModify -Value 1 -PropertyType DWord -Force
}Else{
    New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name NoModify -Value 0 -PropertyType DWord -Force
}
If($CanRemove -eq $false){
    New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name NoRemove -Value 1 -PropertyType DWord -Force
}Else{
    New-ItemProperty -Path "$UninstallPath\$DisplayName" -Name NoRemove -Value 0 -PropertyType DWord -Force
}
}

The function below removes a program entry from Programs and Features (Add/Remove Programs):

Function Remove-ProgramEntry{
<#
.SYNOPSIS
    Removes an entry from Programs and Features (Add/Remove Programs)
.DESCRIPTION
    This function removes a key in the 32-bit registry. Useful when you have a custom packaged application
    that you want to be inventoried by SCCM.
.EXAMPLE
    Remove-ProgramEntry -DisplayName "My Awesome App"
.PARAMETER DisplayName
    The name of the program displayed in Programs and Features
.NOTES
#>
param(
    [Parameter(Mandatory = $true)]
    [string] $DisplayName
)

If($is64Bit){
    $UninstallPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
}Else{
    $UninstallPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
}

If(Test-Path "$UninstallPath\$DisplayName"){
    Remove-Item -Path "$UninstallPath\$DisplayName" -Recurse -Force
}
}