Skip to main content
powershell

Use Powershell to create a “fake” program in the programs and features list for indexing purposes

For a reason I won’t go in to here I recently had to create a fake program in the programs and features list of a computer. One example when this might be useful is for indexing purposes but there are other usecases for it as well.

Since this list is saved in the registry adding a new program to it is easy. I tend to follow the “code should document itself” approach since I never know who might have to modify my code at a later date, to that end I decided to make a function out of this instead of adding a lot of stuff to the registry inside the main script.

If you find another usecase for this script I would be happy to hear it.

Function New-PopsFakeProgram{
<#
.SYNOPSIS
    Add a fake program to programs & features
.DESCRIPTION
    Add a fake program to programs & features
.PARAMETER Name
    The internal name
.PARAMETER DisplayName
    The name that should be shown
.PARAMETER Publisher
    The name of the publisher
.PARAMETER DisplayVersion
    The version number
.PARAMETER DisplayIcon
   Path to a display icon, can be an exe file
.PARAMETER UninstallString
    The string for uninstalling the program
.EXAMPLE
    New-PopsFakeProgram -Name "MyFakeProgram" -DisplayName "My fake program"
.NOTES
.LINK
    popeen.com/2020/03/13/use-powershell-to-create-a-fake-program-in-the-programs-and-features-list-for-indexing-purposes
#>

    Param(
        [Parameter(Mandatory=$true)]
                         [ValidateNotNullorEmpty()]
                         [string]$Name,
        [Parameter(Mandatory=$true)]
                         [ValidateNotNullorEmpty()]
                         [string]$DisplayName,
        [Parameter(Mandatory=$false)]
                         [ValidateNotNullorEmpty()]
                         [string]$Publisher = "Dummy",
        [Parameter(Mandatory=$false)]
                         [ValidateNotNullorEmpty()]
                         [string]$DisplayVersion = $(Get-Date -Format "yyyy.dd.MM.HHmm"),
        [Parameter(Mandatory=$false)]
                         [ValidateNotNullorEmpty()]
                         [string]$DisplayIcon = "C:\Windows\explorer.exe",
        [Parameter(Mandatory=$false)]
                         [ValidateNotNullorEmpty()]
                         [string]$UninstallString = "DummyUninstall"
    )

    if( -not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -PathType Container) )
            {
                         New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Name $Name | Out-Null
            }
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayName" -Type String -Value $DisplayName -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "Publisher" -Type String -Value $Publisher -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayVersion" -Type String -Value $DisplayVersion -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayIcon" -Type String -Value $DisplayIcon -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "UninstallString" -Type String -Value $UninstallString -Force | Out-Null

}
Function Remove-PopsFakeProgram{
<#
.SYNOPSIS
    Remove a program from programs & features
.DESCRIPTION
    Remove a program from programs & features
.PARAMETER Name
    The internal name, this is probably not the one you see in programs & features
.EXAMPLE
    Remove-PopsFakeProgram -Name "MyFakeProgram"
.NOTES
.LINK
    popeen.com/2020/03/13/use-powershell-to-create-a-fake-program-in-the-programs-and-features-list-for-indexing-purposes
#>
    Param(
        [Parameter(Mandatory=$true)]
                         [ValidateNotNullorEmpty()]
                         [string]$Name
    )
    if( Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -PathType Container )
    {
        Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Recurse -Force  
    }
    
}

Share

Deleting domains from your pihole history database

For a while I have had an error in my home automation system that caused my hub to do hundreds of request to popeen.com every night. Today I finally sat down and fixed it and once it was fixed I also wanted to purge all the lines from the database so it doesn’t screw up my statistics anymore. Doing so was fairly simple but took me a few minutes to figure out so I decided to write it down here. That way I can come back here whenever I need to do it again and hopefully help someone else out at the same time.

First you SSH into the server running pihole, I am assuming you know how to do that already and if not there are plenty of guides for it if you google it so I won’t cover it here.

The first thing we need to do is shutdown pihole so we are free to modify the database, to shut down pihole run the command

sudo service pihole-FTL stop

Then we need to access the database, we do so by running the command

sudo sqlite3 /etc/pihole/pihole-FTL.db

ok, now it’s time to delete the domain, we do this by running this command, replace popeen.com with the domain you want to purge.

delete from queries where domain = "popeen.com";

when you have purged all the domains you want we exit the database by hitting CTRL + C

and lastly we start pihole up again by running

sudo service pihole-FTL start
Share