Set ConfigMgr client Inventory Settings with PowerShell

This PowerShell code is designed to create new custom Device client settings and then enable and configure those settings for Software Inventory, as per Chapter 6 in “Learn ConfigMgr in a Month of Lunches“.

A few things to note about this code:

  1. Similar to the PowerShell code used to create and configure Active Directory Group Discovery, the WMI class which contains the settings objects/instances (SMS_ClientSettings) is not the one you need to work with in order to configure the inventory settings, which in this case is SMS_SoftwareInventoryAgentConfig
  2. Note the Property array which is built using the SMS_SoftwareInventoryAgentConfig class – you need to specify the type of data for each line, otherwise the default is STRING, which will throw an error when you try to write it back to the instance in SMS_ClientSettings

The code is designed for the lab environment in the book, but the process will work in any ConfigMgr 2012 R2 environment.

# Define Configuration Manager variables
$CMSiteCode = 'P01'
$CMSiteServer = ''
$CMNameSpace = "rootSMSsite_$CMSiteCode"
$CustomSettingsName = 'Desktop Software Inventory Settings'
# 1.0 Create new Client Settings
New-CMClientSetting -Name $CustomSettingsName -Type Device
# 1.1 Enable Software Inventory
Set-CMClientSetting -Name $CustomSettingsName `
  -SoftwareInventorySettings `
  -EnableSoftwareInventory $true
# 1.2 Configure Software Inventory Settings
$Settings = Get-CimInstance -ComputerName $CMSiteServer -Namespace $CMNameSpace -ClassName SMS_ClientSettings | Where-Object {$_.Name -eq $CustomSettingsName}
$InventorySettings = New-CimInstance -ClientOnly `
  -Namespace $CMNameSpace `
  -ClassName SMS_SoftwareInventoryAgentConfig `
  -Property @{AgentID=[uint32]'2';
$settings.AgentConfigurations += $InventorySettings
Get-CimInstance -ComputerName $CMSiteServer -Namespace $CMNameSpace -ClassName SMS_ClientSettings | Where-Object {$_.Name -eq $CustomSettingsName} | Set-CimInstance -Property @{AgentConfigurations=$Settings.AgentConfigurations}

2 comments to Set ConfigMgr client Inventory Settings with PowerShell

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>