Using and troubleshooting Scan-CustomRegistry.ps1
This article provides an overview of the Scan-CustomRegistry.ps1 script, which is used to scan custom Windows registry key properties and report them to the Snow Inventory Agent. It also covers common troubleshooting steps to help resolve issues with the script.
How the script works
What Scan-CustomRegistry.ps1 does
The script is designed to scan specified Windows registry keys and properties and report them to the Snow Inventory Agent as software or registry data. It reads the custom keys from a Keys.CSV file and attempts to collect values from those locations.
When creating a Snow agent for Windows, the Package Builder provides both the Scan-CustomRegistry.ps1 and the Keys.CSV files.
CSV input structure
The script expects a Keys.csv file to be placed in:
C:\Program Files\Snow Software\Inventory\Agent
Required format:
The first row of the file is the header and must not be removed.
Each row must define:
- key: The registry path: HKLM:\SOFTWARE\Example
Be aware HKEY_local_Machine should be changed to HKLM: in thekeys.csv. - property: The name of the registry value to retrieve.
The property value needs to be separated (delimiter) from the registry key with a semicolon.- In the example below, we are looking for the “DisplayVersion” property within the registry key and will retrieve its value.
Example:HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E2CB22A5-9902-4F90-8FE7-B74B3C3EF874};DisplayVersion
- In the example below, we are looking for the “DisplayVersion” property within the registry key and will retrieve its value.
- lognotfound (optional): true/false, whether to log missing properties or keys in the
inv3.xml
How the script processes data
The script includes key functions that handle scanning and reporting:
_yieldRegistryKey: Reports a registry key/value to the agent_yieldSoftware: Reports the key/value as a software entry_getCustomRegKeys: Parses the CSV and calls scanning logic
These functions work together to ensure the registry keys are read correctly and reported into Snow Inventory data.
How the script executes
The script follows this flow:
- Checks if
Keys.csvexists. - Reads each row and attempts to access the defined key and property.
- If successful, reports the registry data using the Snow Inventory File Extractor:
C:\Program Files\Snow Software\Snow Inventory\Server\SnowInventoryFileExtractor.exe
- If the key or property is not found, logs a message in
inv3.xml(if lognotfound is set to true).
Troubleshooting tips
If the script is not running as expected:
- Make sure
Keys.csvuses the correct ; delimiter. - Verify permissions allow access to the defined registry keys.
- Test registry access manually using PowerShell.
- Check the command prompt output when manually running the SnowAgent scan.
- Review script version and changelog for known issues or changes.
Common issues and solutions
Scenario 1: Key not found
If lognotfound is enabled, missing keys or properties will be logged in inv3.xml.
For example, if the registry key is incorrectly defined using HKEY_LOCAL_MACHINE instead of HKLM:, the script will not find the key.
Correct format:
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{GUID};DisplayVersion
Be sure to check the registry key path formatting carefully.
Scenario 2: Property not defined
You may see the following warning in the command prompt:
WARNING: Scan-CustomRegistry - something went wrong. Cannot bind argument to parameter 'Property' because it is an empty string.
This happens if the property field in Keys.csv is blank or missing.
Ensure both the registry path and the property name are correctly defined in Keys.csv.
IMPORTANT: The script will not validate if the registry key itself is correct. Always check the registry manually or use the RegistryKeyAccessTest.ps1 script to confirm access.
Compatibility notes
- The script is compatible with PowerShell 2.0 and higher.
- It uses compatibility functions to support older Snow agent versions.
- The script file should be saved with UTF-8 BOM encoding to avoid hash mismatch errors.
Summary
The Scan-CustomRegistry.ps1 script helps capture custom registry data for reporting through the Snow Inventory Agent. Following the correct Keys.csv format, ensuring registry paths and properties are valid, and using the provided troubleshooting tips will help resolve common issues.