Skip to content

How to get CIs updated by specified connector with supported way

How to get CIs updated by specified connector with supported way published on 4 Comments on How to get CIs updated by specified connector with supported way

As you know when you deleted connector in SCSM all configuration items discovered (or imported) by this connector will also be deleted. But good question is how determinate which CIs will be deleted? This can be done using some SQL queries but this is complex, unsupported way and you must have SQL Management Studio installed. But we have a power of PowerShell and can use it to get this information.

UPDATED: Thanks to Aaron to pointing me to the right direction. Approach below allows you get CIs updated by specified connector. But SCSM stores all connectors for CI object and even if no properties was updated during connector’s sync process, this connector will be added to object. In other words, if you have object that discovered by more than one connector then this object will be removed only if all connectors will be removed.

Each object in SCSM have a generic properties like Id (internal ID), DisplayName and other. Those properties aren’t defined in any classes. One of those generic properties is LastModifiedBy. This property store the ID of the connector that last modified this object. For instance:
image

The next question is how to get connector’s ID. This is very simple by using native SCSM cmdlets (Get-SCSMConnector) but it can be little bit complex by using SMLets. But this is shouldn’t be a problem for you if you remember my old article about changing AD Connector scheduler. I will publish both scripts.

To get CI’s updated by specified connector using native SCSM cmdlets:

param(
    [Parameter(Mandatory=$true)]
    $connectorDisplayName
)
$ciClass = Get-SCSMClass -Name "System.ConfigItem"
$connectorObj = Get-SCSMConnector | ? {$_.DisplayName -eq "$connectorDisplayName"}
$connectorId = $connectorObj.ConnectorID


$allCIs = (Get-SCSMClassInstance -Class $ciClass -Filter "LastModifiedBy -eq $connectorId")
$allCIs | select DisplayName, @{Name="Class";Expression={$_.EnterpriseManagementObject.GetLeastDerivedNonAbstractClass().DisplayName}}

Usage: Get-SCSMObjectsByConnector.ps1 “AD Main”

To get CI’s updated by specified connector using SMLets and SDK:

param(
    [Parameter(Mandatory=$true)]
    $connectorDisplayName
)

Import-Module SMLets

$ciClass = Get-SCSMClass -Name "System.ConfigItem"

# additional DLL
$SMADDDLL    = "${SMSDKDIR}\Microsoft.EnterpriseManagement.ServiceManager.dll"

[reflection.assembly]::LoadFile($SMADDDLL) | out-null

# Connect to SCSM server, please check the server name
$ServiceManagementGroup = new-object Microsoft.EnterpriseManagement.ServiceManagementGroup "localhost"

# Get connector
$connectorObj = $ServiceManagementGroup.ConnectorFramework.GetConnectors() | ? {$_.DisplayName -eq "$connectorDisplayName"}

if($connectorObj)
{
    $connectorId = $connectorObj.Id
    $allCIs = Get-SCSMObject -Class $ciClass -Filter "LastModifiedBy = '$connectorId'"
    $allCIs | select DisplayName, @{Name="Class";Expression={$_.GetLeastDerivedNonAbstractClass().DisplayName}}
}

Usage: Get-SCSMObjectsByConnectorSDK.ps1 “AD Main”

Share

4 Comments

Leave a Reply

Primary Sidebar

%d bloggers like this: