Retire CI from Intune
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 02:18 AM
Hello All,
I have a SG- Intune integration running, I want to retire CI's that are present in ServiceNow but not in Intune, can I write a script logic for this to identify them and retire them ?
Regards,
Anmol
#itom
#discovery
#intune
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 02:29 AM
Yes, you can write a script in ServiceNow to retire Configuration Items (CIs) that are present in ServiceNow but not found in Intune. To achieve this, Identify CIs in ServiceNow, Identify CIs in Intune, Compare CIs and Retire the Missing CIs.
(function() {
var snCiTable = 'cmdb_ci_computer';
var intuneCiTable = 'intune_device_inventory';
// Get the list of CIs in ServiceNow (CMDB)
var serviceNowCIs = new GlideRecord(snCiTable);
serviceNowCIs.query();
while (serviceNowCIs.next()) {
var snCiSerial = serviceNowCIs.serial_number;
var intuneCi = new GlideRecord(intuneCiTable);
intuneCi.addQuery('serial_number', snCiSerial);
intuneCi.query();
if (!intuneCi.next()) {
serviceNowCIs.state = 6; // 6 = Retired in the state field
serviceNowCIs.update();
gs.info('Retired CI with Serial Number: ' + snCiSerial);
}
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 07:54 AM
You should be leveraging a retirement CMDB policy to retire devices not discovered within your given threshold. This will then work on a continuous basis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 09:07 AM - edited 02-28-2025 09:09 AM
Hi @anmolsarasw
You can use cmdb data manager retire policy
Or if you wants to change the state of the CI's from operational to Retire make use of Update Jobs under Data Management module Mark them as retired.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2025 06:58 AM
Hi @anmolsarasw,
To retire CIs that are present in ServiceNow but not in Intune, you can approach it in several ways using the CMDB Data Manager features and scripting options available in ServiceNow.
1. From the Form by Setting the Operational Status to "Retired" (via List View Topology)
You can manually retire CIs by navigating to their records in ServiceNow and setting their Operational Status field to Retired.
Alternatively, you can use List View Topology in ServiceNow to quickly identify and retire multiple CIs at once. To do this:
- Navigate to the CMDB table (e.g.,
cmdb_ci_computer
or the relevant CI table). - Apply any necessary filters to find the CIs that are present in ServiceNow but not in Intune.
- Use the List View to select multiple CIs at once.
- From the list, you can bulk update the Operational Status to Retired by selecting the CIs and using the Update Set functionality or List Actions to set their status to Retired.
This method is great for bulk operations and is faster than editing each CI individually. However, it's still a manual process.
2. Via CMDB Data Manager (as mentioned in the details)
In the CMDB Workspace, you can create or activate a life-cycle rule for a class, including a Retirement Definition. This retirement rule will define how CIs should be retired within your organization.
Specifically, the Retirement Definition can be configured to automatically retire CIs based on certain conditions, such as if they are present in ServiceNow but not in Intune.
Steps:
- Navigate to CMDB Workspace > Management > Data Manager.
- Under Manage retirement definitions, activate or create a retirement definition.
- Set the Condition to reflect the rule for retiring CIs that are no longer in Intune but are in ServiceNow.
- Save and apply the definition.
3. Via Scheduled Job with Script Logic
If you want to automate the process, you can write a scheduled script to identify CIs that are present in ServiceNow but not in Intune, and then retire them.
Steps:
- Create a Scheduled Job in ServiceNow that runs on a regular basis (e.g., daily or weekly).
- In the script, write logic to compare the list of CIs in ServiceNow with the list of CIs in Intune.
- Any CIs in ServiceNow but not in Intune should have their Operational Status set to Retired.
Sample Script Logic:
// Define a scheduled job to retire CIs in ServiceNow but not in Intune
var snCIGr = new GlideRecord('cmdb_ci_computer'); // Adjust for your CI table
snCIGr.addQuery('operational_status', '!=', 'Retired'); // Only target non-retired CIs
snCIGr.query();
while (snCIGr.next()) {
var intuneCI = checkIfCIInIntune(snCIGr.sys_id); // Call an external integration or query Intune data
if (!intuneCI) {
snCIGr.operational_status = 'Retired'; // Set to retired if not found in Intune
snCIGr.update();
}
}
// Example function to check if CI exists in Intune
function checkIfCIInIntune(ciSysId) {
// Logic to query Intune for the CI matching ServiceNow's CI (e.g., via API or data sync)
// Return true if found, false otherwise
return false; // Simulating that CI is not found in Intune
}
You can use APIs or other integration methods to check if the CI exists in Intune. If not, set the Operational Status of the CI to Retired.
Additional Notes:
- Managing Dependent CIs: Make sure to enable dependent CI management when you retire a CI. This ensures that any dependent CIs are also retired and prevents orphaned CIs.
- Single Life-cycle Rule: Each class can only be associated with a single life-cycle rule. This is important when configuring the retirement definitions for different CIs.
Conclusion:
- You can retire CIs using the manual method by changing the Operational Status to Retired.
- You can automate retirement by creating or activating a retirement definition in the CMDB Data Manager.
- For a more customized and automated approach, you can write a script in a Scheduled Job to compare the data between ServiceNow and Intune and retire CIs accordingly
If you believe the solution provided has adequately addressed your query, could you please **mark it as 'Helpful'** and **'Accept it as a Solution'**? This will help other community members who might have the same question find the answer more easily.
Thank you for your consideration.