I have this function that do a "SELECT" query to find computers in SCCM. I do get get some objects, but not all computers are found, even that I can see them in the SCCM console. I don't get any errors only that some of the objects are not found.
What could be the issue?
def main(file_path, search_value): # Load the Excel workbook wb = load_workbook(file_path) # Select the active worksheet ws = wb.active # Define wmi_service with a default value of None wmi_service = None try: # Connect to WbemScripting.SWbemLocator locator = win32com.client.Dispatch("WbemScripting.SWbemLocator") # Connect to WMI namespace on the remote computer # Use .ConnectServer for a local connection wmi_service = locator.ConnectServer(sServerName, r'root\SMS\site_'+ sSiteCode) except Exception as e: print("An error occurred:", e) finally: # Create an empty list to store the data from column A Excel_list = [] # Iterate through the rows in column A starting from row 2 for row in range(2, ws.max_row + 1): cell_value = ws['A'+ str(row)].value if cell_value is not None: Excel_list.append(cell_value) # Find elements in AD not present in Excel not_in_Excellist = list(set(search_value) - set(Excel_list)) if wmi_service is not None: for computername in not_in_Excellist: # Query some information from WMI query = f"SELECT * FROM SMS_G_System_COMPUTER_SYSTEM Where Name='{computername}'" results = wmi_service.ExecQuery(query) if results: for item in results: if item.ResourceId != 0: query = f"SELECT * FROM SMS_G_System_PC_BIOS Where RESOURCEID='{item.ResourceId}'" results = wmi_service.ExecQuery(query) for item in results: print("Name:", computername) print("SerialNumber:", item.SerialNumber) else: print(computername +" not found in SCCM.") else: print("Failed to connect to SCCM namespace.")