Administration Guide
PowerShell Examples for Custom Software Recognition
This page collects ready-to-use PowerShell samples for custom software recognition. Copy a sample into the Script box when you create or edit a recognition rule, then replace the placeholder values with data from your environment.
Note: Each recognition script should return a value that matches the software record AlloyScan expects. Use the fields shown in the samples below: Name, Version, Publisher, InstallDate, SerialNumber, and InstallKey.
Before you start
- Create the custom software recognition rule.
- Set the script to detect the software you want AlloyScan to recognize.
- Test the script in a controlled environment before you use it on production devices.
PowerShell script samples
Recognizing software from Windows Registry keys
Use this pattern when the software is registered in the Windows uninstall keys.
$ErrorActionPreference = "SilentlyContinue"
$ProgressPreference = "SilentlyContinue"
$Result = $null
$ProductName = "Example Product"
# --- Registry paths to search for the product ---
$registryPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
# --- Search in Registry ---
$regItem = Get-ItemProperty $registryPaths |
Where-Object { $_.DisplayName -like "*$ProductName*" } |
Select-Object -First 1
if ($regItem) {
$installDate = $null
if ($regItem.InstallDate) {
try {
$parsed = [DateTime]::ParseExact($regItem.InstallDate, "yyyyMMdd", $null)
$installDate = $parsed.ToString("yyyy-MM-ddTHH:mm:ss")
}
catch {
$installDate = $null
}
}
$Result = [PSCustomObject]@{
Name = $regItem.DisplayName
Version = $regItem.DisplayVersion
Publisher = $regItem.Publisher
InstallDate = $installDate
SerialNumber = ""
InstallKey = ""
}
}
$Result
This sample:
- searches the Windows uninstall keys for a product name match;
- returns a software record with the detected version and publisher;
- leaves
SerialNumberandInstallKeyblank when the source does not provide them.
Recognizing software with Get-Package
Use this pattern when the software is available through package metadata.
$ErrorActionPreference = "SilentlyContinue"
$ProgressPreference = "SilentlyContinue"
$Result = $null
$ProductName = "Example Product"
# --- Search in Get-Package (Apps & Features) ---
$pkg = Get-Package |
Where-Object { $_.Name -like "*$ProductName*" } |
Select-Object -First 1
if ($pkg) {
$Result = [PSCustomObject]@{
Name = $pkg.Name
Version = $pkg.Version
Publisher = $pkg.ProviderName
InstallDate = $null
SerialNumber = ""
InstallKey = ""
}
}
$Result
This sample:
- uses
Get-Packageto locate the product; - returns the provider name as the publisher;
- leaves
InstallDateblank when the package source does not provide a date.
Recognizing software from files
Use this pattern for portable applications or software that is easier to identify through an executable file.
$ErrorActionPreference = "SilentlyContinue"
$ProgressPreference = "SilentlyContinue"
$Result = $null
$ProductName = "Example Product"
# --- 1) Search for any EXE containing "Example" in the file name ---
$exe = Get-ChildItem -Path "C:\" -Filter "*.exe" -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like "*Example*" } |
Select-Object -First 1
# --- 2) If not found, search by ProductName in VersionInfo ---
if (-not $exe) {
$exe = Get-ChildItem -Path "C:\" -Filter "*.exe" -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.VersionInfo.ProductName -like "*$ProductName*" } |
Select-Object -First 1
}
# --- 3) Build result only if found ---
if ($exe) {
$ver = (Get-Item $exe.FullName).VersionInfo
$installDate = $exe.CreationTime.ToString("yyyy-MM-ddTHH:mm:ss")
$Result = [PSCustomObject]@{
Name = $ver.ProductName
Version = $ver.FileVersion
Publisher = $ver.CompanyName
InstallDate = $installDate
SerialNumber = ""
InstallKey = ""
}
}
$Result
This sample:
- searches the local disk for a matching executable;
- reads the file version information from the executable;
- converts the file creation timestamp into the date format shown in the sample.