question

Barleyologist avatar image
0 Votes"
Barleyologist asked saldana-msft edited

MEMCM Powershell Get Configuration Item's "Reference's"

Trying to figure out how to get which CM Baseline a specific Configuration Item is referenced in and remove it's reference via Powershell. Trying to use Get-CMConfigurationItem but do not see 'references' and maybe that information is not included, if not is there another way?

windows-server-powershellmem-cm-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AllenLiu-MSFT avatar image
0 Votes"
AllenLiu-MSFT answered JohnBlanks-2539 published

Hi, @Barleyologist
Thank you for posting in Microsoft Q&A forum.
I did some research and couldn't find a way to get this information by powershell.
However, we can get this from SCCM console, check the configuration item's relationships of properties, and select "Configuration baselines that reference this configuration item", it will show the information.
110141-13.jpg


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



13.jpg (52.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is not an answer to the question that is asked.

0 Votes 0 ·
SherryKissinger-ECM avatar image
0 Votes"
SherryKissinger-ECM answered

This also doesn't answer the specific question (it's asking about references via Powershell); but via SQL query, this works for me.

Select Baseline.DisplayName as 'BaselineName', ciinfo.DisplayName as 'CIName', *
from fn_ListConfigurationBaselineInfo(1033) Baseline
join vSMS_CombinedConfigurationItemRelations cir on cir.FromCI_ID=Baseline.CI_ID
join v_ConfigurationItems ci on ci.CI_ID=cir.ToCI_ID
join fn_ListCIs(1033) ciinfo on ciinfo.ci_id=cir.ToCI_id
where ciinfo.DisplayName = 'The Exact Name of a Configuration Item'

If that answer still is useless (it might be); you may need to submit a request to support, and see if there is a way currently, and if not, to request that a Powershell cmdlet be created or enhanced to address your requirement.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnBlanks-2539 avatar image
1 Vote"
JohnBlanks-2539 answered JohnBlanks-2539 published

The reason I this question caught my eye was i want to act on all the references of a given CI. You know like be able to remove the references without having to hunt the individual baselines down so I can delete a CI. So I wrote this Powershell function that will remove the references from any baseline that references it. I know it is not the cleanest code but it works like a champ in my environment where I have over 700 baselines.

My Function is meant for interactive use and prompts you before it removes the CI References. If more than one CI is found matching the CIName it will ask you to be more specific.


 Function Remove-CIFromBaselines {
     Param (
             [Parameter(Mandatory)]
             [String] $CIName
                
     ) 
     $ciObject = (get-CMConfigurationItem  -Name $CIName -fast)
     $count = $ciObject.count 
     If ($count -gt 1) {
         Write-Output "There are [$count] CIs in MECM named [$CIName]. Please be more specific..." 
         Break
     } ELSEIF ($count -eq 0) {
         Write-Output "There are [$count] CIs in MECM named [$CIName]. Please be more specific..." 
         Break
     }
     $AllBaselines= Get-CMBaseline -fast
     $baselinecount = $allbaselines.count
     Write-Output "There are [$baselinecount] total baselines to analyze - This could take a few minutes."
     $prompt = Read-host -Prompt "Are you sure you want to remove All Referennces to [$CIName]? (Y/N) "
     If ($Prompt -ne "Y") {Break}
     $prompt = Read-host "Type `'I ConFirm`' to continue" 
     If ($Prompt -eq "I Confirm" -and $prompt -cmatch "I ConFirm") {        
         $CIID = $CIObject.CI_ID
         $LastIndex = $CIobject.CI_UniqueID.lastIndexof("_") +1
         $length = $CIObject.CI_UniqueID.substring($lastIndex).length - 2
         $CIUniqueID = $CIObject.CI_UniqueID.substring($lastIndex,$length)
         Write-Output "The CIUniqueID is [$CIUniqueID]" 
         $affectedList = New-Object System.Collections.ArrayList
         $modifiedList = New-Object System.Collections.ArrayList
         ForEach ($baseline in $AllBaseLines) {
             $baselineName = $Baseline.localizedDisplayName
             Write-Output "Analyzing [$baselineName] for reference to [$CIName]" 
             $XMLContent = $baseline | get-CMBaselineXMLDefinition
             If ($XMLContent.contains($CIUniqueID)){
                 $AffectedList.Add($BaselineName) |out-Null
                 Write-Output "[$baselineName] contians [$CIName]" 
                 # Check if it is a OS or An Application CI - 3 = OS ; 5 = Required Application CI - https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/compliance/sms_configurationitemlatestbaseclass-server-wmi-class
                 If ($CIObject.CIType_ID -eq 3) {
                     $Baseline |Set-CMBaseline -RemoveOSConfigurationItem $CIObject.CI_ID
                     $Modifiedlist.Add($Baselinename) |out-null
                 }
                 If ($CIObject.CIType_ID -eq 5) {
                     $Baseline |Set-CMBaseline -RemoveRequiredConfigurationItem $CIObject.CI_ID
                     $Modifiedlist.Add($Baselinename) |out-Null
                 }
             }
         }
         $countofAffected = $AffectedList.count
         $countofmodified = $ModifiedList.Count
         Write-Output "#################################### SUMMARY ####################################################" 
         Write-Output "There were [$countofAffected] Baselines that contain [$CIName]. [$countofmodified] were updated to remove the reference to [$CIName]" 
         If ($countofAffected -eq $countofmodified) {
             ForEach ($item in $AffectedList) {
                 Write-Output "Baseline [$item] contained [$CIName]" 
             }
             ForEach ($item in $ModifiedList) {
                 Write-Output "[$CIName] was removed from [$Item]"
             }
         }
         Write-Output "#################################################################################################" 
     } ELSE {
         Write-Output "Bailing since you did not confirm"
     } 
 }



Hope this helps.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.