Sometimes you might want to force a ConfigMgr client to send a full hardware inventory report immediately for whatever reason. Typically you would simply clean out the WMI instance for the InventoryAction then trigger the schedule. But sometimes there may already be a scheduled action in the queue, for example the hardware inventory cycle has been triggered on the normal schedule but it runs with randomization so it doesn’t run immediately when it’s triggered. In this case, you get a message in the InventoryAgent.log that looks like this:
Inventory: Message [Type=InventoryAction, ActionID={00000000-0000-0000-0000-000000000001}, Report=Delta] already in queue. Message ignored.
It ignores your request if there’s already a request queued.
You can still force it to run immediately though by clearing the queue. To do this you can simply delete the InventoryAgent queue folder but you can’t do this while the SMS Agent host service is running, you have to stop the service first.
Below is a script that will attempt to trigger a full a HWI report and check the InventoryAgent.log to see if the request was ignored – if so, it clears the queue and tries again.
# Invoke a full (resync) HWI report
$Instance = Get-CimInstance -NameSpace ROOT\ccm\InvAgt -Query "SELECT * FROM InventoryActionStatus WHERE InventoryActionID='{00000000-0000-0000-0000-000000000001}'"
$Instance | Remove-CimInstance
Invoke-CimMethod -Namespace ROOT\ccm -ClassName SMS_Client -MethodName TriggerSchedule -Arguments @{ sScheduleID = "{00000000-0000-0000-0000-000000000001}"}
Start-Sleep -Seconds 5
# Check InventoryAgent log for ignored message
$Log = "$env:SystemRoot\CCM\Logs\InventoryAgent.Log"
$LogEntries = Select-String –Path $Log –SimpleMatch "{00000000-0000-0000-0000-000000000001}" | Select -Last 1
If ($LogEntries -match "already in queue. Message ignored.")
{
# Clear the message queue
# WARNING: This restarts the SMS Agent host service
Stop-Service -Name CcmExec -Force
Remove-Item -Path C:\Windows\CCM\ServiceData\Messaging\EndpointQueues\InventoryAgent -Recurse -Force -Confirm:$false
Start-Service -Name CcmExec
# Invoke a full (resync) HWI report
Start-Sleep -Seconds 5
$Instance = Get-CimInstance -NameSpace ROOT\ccm\InvAgt -Query "SELECT * FROM InventoryActionStatus WHERE InventoryActionID='{00000000-0000-0000-0000-000000000001}'"
$Instance | Remove-CimInstance
Invoke-CimMethod -Namespace ROOT\ccm -ClassName SMS_Client -MethodName TriggerSchedule -Arguments @{ sScheduleID = "{00000000-0000-0000-0000-000000000001}"}
}
Thanks a lot for this script Trevor. Very useful. It fixed the hardware inventory for one of my machines. If I do a collection with all machines with Hardware inventory failed for while, do you think it’s wise to deploy that script ;to that collection? What are your thoughts on this?
Thanks in advance for your response
Do it 🙂 Why not?
This worked perfectly! Thanks a lot, Trevor!
This is a great post thhanks