1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Param ( [string]$ComputerName = $env:COMPUTERNAME, [string]$Application ) Write-Host "Getting information from computer $ComputerName." if ($Application) { Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\clientsdk -Class CCM_Application | Where-Object {$_.Name -like "*$Application*" } | Select-Object Name, Revision, InstallState, ApplicabilityState, ConfigureState | Sort-Object Name | Format-Table -AutoSize } else { Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\clientsdk -Class CCM_Application | Select-Object Name, Revision, InstallState, ApplicabilityState, ConfigureState | Sort-Object Name | Format-Table -AutoSize } |
Month: November 2021
Delete root\ccm namespace with PowerShell
Delete the root\ccm namespace on the local computer.
1 |
Get-WmiObject -query "Select * From __Namespace Where Name='CCM'" -Namespace "root" | Remove-WmiObject |
Delete the root\ccm namespace on a remote computer.
1 2 |
$Server = "ServerName" Get-WmiObject -query "Select * From __Namespace Where Name='CCM'" -Namespace "root" -ComputerName $Server | Remove-WmiObject |
Clear SCCM Cache
Borrowed from https://sccm-zone.com/deleting-the-sccm-cache-the-right-way-3c1de8dc4b48
Using the PowerShell code below will clear the ConfigMgr cache the correct way.
1 2 3 4 5 6 7 8 9 10 |
## Initialize the CCM resource manager com object [__comobject]$CCMComObject = New-Object -ComObject 'UIResource.UIResourceMgr' ## Get the CacheElementIDs to delete $CacheInfo = $CCMComObject.GetCacheInfo().GetCacheElements() ## Remove cache items ForEach ($CacheItem in $CacheInfo) { $null = $CCMComObject.GetCacheInfo().DeleteCacheElement([string]$($CacheItem.CacheElementID)) } |
Collection query for reporting
In order to add a collection prompt to a custom report you need to add an additional dataset to your report that queries for all available collections, includes the collection name and ID, and sorts the list by name.
Below an an example of the required code to retrieve all collections from ConfigMgr.
1 2 3 |
SELECT CollectionName, CollectionID FROM v_Collections ORDER BY CollectionName |
Below is the output from SSMS.
To use the query in a report you need to add a new dataset. In this example the dataset is called “AllCollections.”
Now we can add the collection query to the report and the main dataset.
In order to make a report utilize the collection query, we need to add the view v_FullCollectionMembership_Valid to the report and join it to v_R_System_valid on the ResourceID column.
Now we need to modify the main report query to take advantage of the ConfigMgr collections. This is accomplished by modifying the report to filter on a variable. You do this by checking the box next to the “CollectionID” column from v_FullCollectionMembership_Valid box.
Now we’re ready to add the filter. Under the “Filter” column in the “CollectionID” row, enter ‘=@CollID’ without the quotes.
Now when you run the query you’ll be prompted for a collection ID. In the screenshot, SMS00001, or All Systems, is used.
Results from the query.