ConfigMgr
My Two Favorite ConfigMgr Run Scripts
Topics: ConfigMgr
I do a lot of work in the ConfigMgr inventory and reporting space, and I also help a lot of folks troubleshoot issues involving inventory and reporting. In this blog post, I share with you two of my favorite ConfigMgr run scripts which are very useful when it comes to troubleshooting these types of problems. One helps when you need to force a full hardware inventory and the other is great when you need to force a re-scan of software updates.
Earlier this month, you might remember, I published a blog post called, Run Scripts is the Best Feature in SCCM. Within it, I showed you how I used the Run Scripts feature in ConfigMgr/SCCM to turn a firewall off remotely. In today’s post, I show you, once again, why I think the Run Scripts feature is the best!
Force a Full Inventory – ConfigMgr Run Script
It happens all the time. ConfigMgr is showing outdated details for hardware inventory. Why? The biggest culprit is not correctly setting-up ConfigMgr to leverage hardware inventory by increasing the maximum MIF size to 50 MB. There is an easy fix for this issue and I cover it within my post, How to Increase the Maximum File Size of Management Information Files (MIF). Once you increase the maximum file size, however, you need to force a full hardware inventory on some (or maybe all) of your ConfigMgr clients. Unfortunately, this is a side-effect of not increasing the MIF size when ConfigMgr was first built.
Prior to the Run Scripts feature, you could force a full inventory by creating a package and program, deploying it to a collection, and then finally adding the computer(s) to that collection. This worked, but it took time. When you are troubleshooting an issue, you don’t want to wait, what might seem like forever, for things to happen.
I do not like waiting, so I created a work-around to the package and program solution. Some time ago, I showed you, in another of my blog posts, how to reset all of the inventory items using a scheduled task, How to Avoid Receiving Inventory Re-Sync Requests for Snapshot VMs. Recently, I updated the listed WMIC commands in that blog post to PowerShell and added this new script to my ConfigMgr console. Below is the script.
$comp=”localhost”
$HardwareInventoryID = ‘{00000000-0000-0000-0000-000000000001}’
$SoftwareInventoryID = ‘{00000000-0000-0000-0000-000000000002}’
$HeartbeatID = ‘{00000000-0000-0000-0000-000000000003}’
$FileCollectionInventoryID = ‘{00000000-0000-0000-0000-000000000010}’
Get-WmiObject -ComputerName $comp -Namespace ‘RootCCMINVAGT’ -Class ‘InventoryActionStatus’ -Filter “InventoryActionID=’$HardwareInventoryID'” | Remove-WmiObject
Get-WmiObject -ComputerName $comp -Namespace ‘RootCCMINVAGT’ -Class ‘InventoryActionStatus’ -Filter “InventoryActionID=’$SoftwareInventoryID'” | Remove-WmiObject
Get-WmiObject -ComputerName $comp -Namespace ‘RootCCMINVAGT’ -Class ‘InventoryActionStatus’ -Filter “InventoryActionID=’$HeartbeatID'” | Remove-WmiObject
Get-WmiObject -ComputerName $comp -Namespace ‘RootCCMINVAGT’ -Class ‘InventoryActionStatus’ -Filter “InventoryActionID=’$FileCollectionInventoryID'” | Remove-WmiObject
Start-Sleep -s 5
Invoke-WmiMethod -computername $comp -Namespace rootCCM -Class SMS_Client -Name TriggerSchedule -ArgumentList $HeartbeatID
Invoke-WmiMethod -computername $comp -Namespace rootCCM -Class SMS_Client -Name TriggerSchedule -ArgumentList $HardwareInventoryID
Invoke-WmiMethod -computername $comp -Namespace rootCCM -Class SMS_Client -Name TriggerSchedule -ArgumentList $SoftwareInventoryID
Invoke-WmiMethod -computername $comp -Namespace rootCCM -Class SMS_Client -Name TriggerSchedule -ArgumentList $FileCollectionInventoryID
By the way, further along in this post, I tell you where you can quickly get this script and the software update re-scan script. I also show you where you can find the steps on how to add them to your ConfigMgr console via the Run Scripts feature.
What Does this ConfigMgr Run Script Do?
First, it cleans out all of the previous inventory, so it forces the ConfigMgr client to perform a full inventory. Next, it triggers each of the inventory items from fastest to slowest. This means that Heartbeat Discovery (aka the Discovery Data Collection cycle on the ConfigMgr client computer) and hardware inventory get returned within a few minutes, and the remaining software inventory ones, take hours, if not days, to return.
Force Software Updates to Re-scan ConfigMgr Run Script
Software Update (SU) scan results are state-based messages and sometimes those state-based messages get lost. If the message is lost, when the ConfigMgr client scans for SU at the next scheduled time, the client does NOT return the current state – ever! The only exception is if the state changes (which almost never happens) otherwise nothing is ever sent again.
You may never need to force a re-scan of software updates unless you need to dig deep when determining why the SU status that is shown in ConfigMgr doesn’t match with what is listed on the computer itself. The good news is that most troubleshooting steps (sometimes without you even knowing it) resolve this issue. If they don’t, this script is for you!
Here’s my solution to this problem:
$SCCMUpdatesStore = New-Object -ComObject Microsoft.CCM.UpdatesStore
$SCCMUpdatesStore.RefreshServerComplianceState()
What Does this ConfigMgr Run Script Do?
This very short PowerShell script refreshes the state-based messages of all software updates and returns the results back to ConfigMgr.
How Do You Add These Two Scripts to the ConfigMgr Console?
First, here is a Zip file with both of the scripts below.
ConfigMgr Run Scripts
Second, the step-by-step instructions on how to use the Run Scripts feature are covered in my post, Run Scripts is the Best Feature in SCCM.
In my opinion, these two scripts are two of the most important ones that you need to have within your ConfigMgr script library. Believe me when I say that they help a lot with troubleshooting!
Conclusion: My Two Favorite ConfigMgr Run Scripts
If you have any questions about these PowerShell scripts, setup as ConfigMgr run scripts, please feel free to contact me at @GarthMJ or reach out to Recast Software here.