PowerShell Compare-Object
The “Source of Truth” Audit: Finding Missing Assets in ServiceNow | LazyAdminBlog.com

How to catch the servers that escaped your CMDB using PowerShell.
Every admin knows the struggle: Your discovery tool (Soda) says you have 500 servers, but your CMDB (ServiceNow) only shows 480. Those missing 20 servers are usually the ones that cause the most trouble because nobody is monitoring them or tracking their lifecycles.
Instead of manual VLOOKUP hell in Excel, we can use the “Lazy Admin” way: Compare-Object.
The Logic: Why Compare-Object is King
The heart of this script is the -Property AssetName and the SideIndicator -EQ "<=".
<=means the asset exists in the first list (Soda) but is missing from the second (ServiceNow).- This allows you to pinpoint exactly what needs to be imported or investigated in your CMDB.
The Script: CMDB Gap Analysis
PowerShell
# 1. Load your data sources# Place the Soda List of servers$SodaServers = Import-Csv "C:\Temp\SODAServerAssets.csv"# Place the ServiceNow List of servers$SNServers = Import-Csv "C:\Temp\SNServersMissing.csv"# 2. Define the output$FileLocation = "C:\temp\ServerMissing.csv"# 3. Compare the two lists based on the AssetName property# We use "<=" to find items that exist in Soda but NOT in ServiceNow$MissingServers = Compare-Object $SodaServers $SNServers -Property AssetName | Where-Object {$_.SideIndicator -eq "<="}# 4. Map the results back to the original Soda data to keep all columns (IP, OS, Owner, etc.)$DiffServers = @()foreach ($missedServer in $MissingServers) { $DiffServers += $SodaServers | Where-Object {$_.AssetName -eq $missedServer.AssetName}}# 5. Export the "Clean" list for your next ServiceNow Import$DiffServers | Export-Csv $FileLocation -NoClobber -NoTypeInformationWrite-Host "Audit Complete! Missing servers exported to $FileLocation" -ForegroundColor Green
🛠️ Lazy Admin Tips for this Script:
- Column Headers: Ensure both CSV files have a column named exactly
AssetName. If one is calledNameand the otherHostName, the script will fail. - The “Full Export” Trick: By using the
foreachloop at the end, we aren’t just getting a list of names; we are pulling the entire row from the Soda CSV. This gives you all the metadata (IPs, serial numbers) you need to actually fix the record in ServiceNow. - Automate it: If you can get an API or an automated export from Soda and ServiceNow, you can run this as a scheduled task every Friday afternoon.