Skip to content

Instantly share code, notes, and snippets.

@MrWyss-MSFT
Last active October 5, 2023 14:22
Show Gist options
  • Select an option

  • Save MrWyss-MSFT/9d5d52c17d285981f9eae9cbec413cd7 to your computer and use it in GitHub Desktop.

Select an option

Save MrWyss-MSFT/9d5d52c17d285981f9eae9cbec413cd7 to your computer and use it in GitHub Desktop.
Custom Inventory for Intune: Creates fake software inventory entries (Add Remove Programs / Installed Apps) used to create custom inventory items in Intune
Function New-IntuneInvEntry {
<#
.SYNOPSIS
Creates fake software inventory entries (Add Remove Programs / Installed Apps)
used to create custom inventory items in Intune
.DESCRIPTION
Creates fake software inventory entries in HKLM|HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
with the DisplayName, DisplayVersion, Publisher, InstallDate, NoModify, NoRepair, NoRemove. If it should
be hidden in Add/Remove Programs and Installed Apps it will also set the SystemComponent and WindowsInstaller values to 1.
The Intune Management Extension will read these entries and report them as software inventory.
This can be used to create custom inventory items in Intune
.PARAMETER Prefix
The prefix of the registry key. Default is IntuneInv
.PARAMETER Separator
The separator between the prefix and the name. Default is :
.PARAMETER Publisher
The publisher of the registry key. Default is the prefix
.PARAMETER Name
The name of the registry key. This will be used as the DisplayName
.PARAMETER Value
The value of the registry key. This will be used as the DisplayVersion
.PARAMETER ShowInAddRemovePrograms
If this switch is present the registry key will be visible in Add/Remove Programs
.PARAMETER RunAsUser
If this switch is present the registry key will be created
in HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
.EXAMPLE
New-IntuneInvEntry -Name "Visible" -Value "ShowInAddRemove" -ShowInAddRemovePrograms
.EXAMPLE
New-IntuneInvEntry -Name "Hidden" -Value "HideInAddRemove"
.EXAMPLE
New-IntuneInvEntry -Name "SomeUserValue" -Value "SomeValue" -RunAsUser
.EXAMPLE
New-IntuneInvEntry -Name "SomeUserValueVisible" -Value "SomeValue" -RunAsUser -ShowInAddRemovePrograms -Verbose
.NOTES
Author: Marius Wyss
Date: 2023-10-5
Website: https://ittips.ch
Twitter: @MrWyss-MSFT
GitHub: https://github.com/MrWyss-MSFT
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)] [ValidateLength(1,15)] [String] $Prefix = "IntuneInv",
[Parameter(Mandatory = $false)] [ValidateLength(1,1)] [String] $Separator = ":",
[Parameter(Mandatory = $false)] [ValidateLength(1,64)] [String] $Publisher = $Prefix,
[Parameter(Mandatory = $true)] [ValidateLength(1,48)] [String] $Name,
[Parameter(Mandatory = $true)] [ValidateLength(1,64)] [String] $Value,
[Parameter(Mandatory = $false)] [Switch] $ShowInAddRemovePrograms,
[Parameter(Mandatory = $false)] [switch] $RunAsUser
)
# Set the registry path, if the RunAsUser switch is present use HKCU, else HKLM
$RegPath = "{0}:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -f $(if ($RunAsUser.IsPresent) {"HKCU"} else {"HKLM"})
# Prepare Vars
$KeyName = "$Prefix$Separator$Name"
$RegDate = (Get-Date).ToString("yyyyMMdd")
Write-Verbose -Message "----------------- Creating Registry Key -----------------"
# Create a new Registry key
$RegKey = New-Item -Path $RegPath -Name $KeyName -Force
Write-Verbose -Message "Created Registry Key: $KeyName in $RegPath"
# Set the value of the registry key
# DisplayName as Variable Name
$RegKey | Set-ItemProperty -Name "DisplayName" -Value $KeyName -Force
Write-Verbose -Message "Set DisplayName to $KeyName"
# DisplayVersion as Variable Value
$RegKey | Set-ItemProperty -Name "DisplayVersion" -Value $Value -Force
Write-Verbose -Message "Set DisplayVersion to $Value"
# Publisher to the Prefix
$RegKey | Set-ItemProperty -Name "Publisher" -Value $Publisher -Force
Write-Verbose -Message "Set Publisher to $Publisher"
# Set InstallDate in the yyyymmdd format
$RegKey | Set-ItemProperty -Name "InstallDate" -Value $RegDate -Force
Write-Verbose -Message "Set InstallDate to $RegDate"
# Set NoModify, NoRepair, NoRemove for Add/Remove Programs
$RegKey | Set-ItemProperty -Name "NoModify" -Value 1 -Force
$RegKey | Set-ItemProperty -Name "NoRepair" -Value 1 -Force
$RegKey | Set-ItemProperty -Name "NoRemove" -Value 1 -Force
Write-Verbose -Message "Set NoModify, NoRepair, NoRemove to 1"
# Hide the entry in Add/Remove Programs and Installed Apps
if (-not $ShowInAddRemovePrograms.IsPresent) {
$RegKey | Set-ItemProperty -Name "SystemComponent " -Value 1 -Force
$Regkey | Set-ItemProperty -Name "WindowsInstaller" -Value 1 -Force
Write-Verbose -Message "Set SystemComponent and WindowsInstaller to 1"
}
Write-Verbose -Message "---------------------------------------------------------"
Write-Verbose -Message ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment