SCCM - Software Inventory Import Script
This was a script which I wrote up that can automate adding files and file types which can be added into the Software Inventory using the SCCM SDK script
How the script works
If you have a list of files and file extensions and with wildcards etc.. The script will be able to format the list into the SCCM SDK and create a new client settings configuration and apply the files and file extensions in which will be added to the Software Inventory section.
If the client settings configuration does not exist then it will create it.
Variables to take note of
·$SiteCode – Site code of your SCCM environment
·$File – Location of the list of files and file extensions
·$ClientSettingsName – Name of the client settings which the Software Inventory settings will be updated on
Script
Below is the script
#
#
# Software Inventory Settings Import
# By Dujon Walsham
#
#
#
#
#
#######################################################
# Variables
$SiteCode = "" # Site Code for you SCCM Architecture
$SiteCodeLocation = $SiteCode + ":"
$Computername = $env:COMPUTERNAME
$File = "" # Location for your files which contains the filenames you want to add to the inventory
$Namespace = "root\sms\site_$Sitecode" # Namespace to access your SCCM SDK
$ClientSettingsName = "" # Name for the client settings you want to create
# Connect to SCCM
Import-Module -Name "$(Split-Path $env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
Set-Location $SiteCodeLocation
# Structure Inventory Files
$Files = Import-Csv $File -Header Files
$Search = $files.Count
$inventoriabletypes = $files.files -join " " -split " "
$AllTrue = "True " * $Search -split " "
$AllPath = "* " * $Search -split " "
$AllTruelines = $AllTrue.count -2
$AllPathLines = $AllPath.count -2
$AllTrue = $AllTrue[0..$AllTruelines]
$AllPath = $AllPath[0..$AllPathLines]
$Settings = Get-CimInstance -ComputerName $Computername -Namespace $Namespace -ClassName SMS_ClientSettings | Where-Object {$_.Name -eq $ClientSettingsName}
If ($Settings -eq $null)
{New-CMClientSetting -Name $ClientSettingsName -Type Device}
$Settings = Get-CimInstance -ComputerName $Computername -Namespace $Namespace -ClassName SMS_ClientSettings | Where-Object {$_.Name -eq $ClientSettingsName}
# Create Software Inventory Settings
$InventorySettings = New-CimInstance -ClientOnly `
-Namespace $Namespace `
-ClassName "SMS_SoftwareInventoryAgentConfig" `
-Property @{AgentID=[uint32]'2';
Enabled=[boolean]$true;
Exclude=[String[]]($AllTrue);
ExcludeWindirAndSubfolders=[string[]]($AllTrue);
InventoriableTypes=[string[]]($inventoriabletypes);
Path=[string[]]($AllPath);
ReportOptions=[uint32]'7';
Schedule='0001200000100038';
SubDirectories=[string[]]($AllTrue)}
$Settings.AgentConfigurations += $InventorySettings
# Apply Software Inventory Settings
Get-CimInstance -ComputerName $Computername -Namespace $Namespace -ClassName SMS_ClientSettings | Where-Object {$_.Name -eq $ClientSettingsName} | Set-CimInstance -Property @{AgentConfigurations=$Settings.AgentConfigurations}



