List Systems with Bad MIFs

Posted on Updated on

Today I was troubleshooting some client communication problems and found that one of the causes was that they were generating bad MIFs, so SCCM was rejecting the hardware inventory they were sending.  Along the way, I also found that there 230 bad MIFs on my site server.  Instead of manually opening each file to ‘document’  which system it was, I decided to script it.  I must give credit to a blog posting by Don Hite, which gave me the original idea to do this in the first place.

' AUTHOR : Nick Moseley,
' DATE   : 5/14/2009
' UPDATE : 10/29/2014 - Added code to output the SMS Unique Identifier
' COMMENT: Ensure the value for sSMSInbox is the UNC path to your SCCM inboxes
Const ForReading = 1
Dim sSMSInbox, sNamePosition, bNameFound, sFileLine, sSystemName, iFileCount, oExcel, iRow
sSMSInbox = "\\ServerName\SMS_xyz\inboxes"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oBadDDRFolder = oFSO.GetFolder(sSMSInbox & "\\BAD_DDRS")
Set cBadDDRFiles = oBadDDRFolder.Files
Set oBadMIFFolder = oFSO.GetFolder(sSMSInbox & "\auth\\BADMIFS")
Set colBadMIFFiles = oBadMIFFolder.Files
Set oExcel = CreateObject("Excel.Application")

' Create Excel Spreadsheet and Header
oExcel.Visible = True
Set oWorkbook = oExcel.Workbooks.Add
Set oWorksheet = oWorkbook.Worksheets(1)
iRow = 1
oExcel.Cells (iRow,1) = "System Name"
oExcel.Cells (iRow,2) = "File Name"
oExcel.Cells (iRow,3) = "File Date"
oExcel.Cells (iRow,4) = "File Size (MB)"
oExcel.Cells (iRow,5) = "SMS Unique ID"
' End Create

iFileCount = 0
For each oFile In colBadMIFFiles
    iFileCount = iFileCount + 1
    iRow = iRow + 1
    Set oMIFFile = oFSO.OpenTextFile (oFile.Path, ForReading, True)
    bNameFound = False
    Do Until bNameFound
        sFileLine = CStr (oMIFFile.ReadLine)
        sNamePosition = InStr (sFileLine, "<NetBIOS Name>")
        If sNamePosition > 1 Then
            sSystemName = Replace (Right (sFileLine, len(sFileLine) - (sNamePosition+14)), ">", "")
            sFoundBug = InStr (sSystemName, "//Client")
            If sFoundBug > 0 Then
                ' This is to fix a bug in the script which is undetermined
                ' Do Nothing
                oExcel.Cells (iRow,1) = sSystemName
                oExcel.Cells (iRow,2) = oFile.Name
                oExcel.Cells (iRow,3) = oFile.DateLastModified
                oExcel.Cells (iRow,4) = (oFile.Size/1024)/1024
                bNameFound = True
            End if
        End If
    Set oMIFFile = oFSO.OpenTextFile (oFile.Path, ForReading, True)
	bGuidFound = False
    Do Until bGuidFound
        sFileLine = CStr (oMIFFile.ReadLine)
        sNamePosition = InStr (sFileLine, "UniqueID")
        If sNamePosition > 1 Then
            sGUID = Replace (Right (sFileLine, len(sFileLine) - (sNamePosition+8)), ">", "")
                oExcel.Cells (iRow,5) = sGUID
                bGuidFound = True
        End If

oExcel.Selection.Interior.ColorIndex = 19
oExcel.Selection.Font.ColorIndex = 11
oExcel.Selection.Font.Bold = True
oExcel.Cells.HorizontalAlignment = -4131
Set oExcelRange = oWorksheet.UsedRange
Set oExcelRangeA1 = oExcel.Range("A1")
oExcelRange.Sort oExcelRangeA1, 1, , , , , , 1
WScript.Echo "File Count: " & iFileCount

Also, see a great post by Nick Aquino detailing how bad mifs come to exist –

10 thoughts on “List Systems with Bad MIFs

    Virtual_JTW said:
    August 12, 2010 at 1:11 pm

    Nice script – really helped me out. Small bug/typo though – lines 32 and 59 should be (iRow,4) instead of repeating (iRow,3) twice. At least this fixed it for me using Excel 2007.
    Thanks again.

      Nicolas Moseley responded:
      August 13, 2010 at 11:26 am

      Thanks for catching that and letting me know. That’s what I get for doing a copy/paste!

        dana said:
        October 18, 2010 at 6:09 am

        Really helped me out as well. Thanks for taking the time.

    Killragtshirts said:
    October 31, 2010 at 6:32 pm

    Thanks mate worked a treat.

    List Systems with Bad MIFs - Chris Nackers Blog said:
    November 23, 2010 at 2:45 pm

    […] Read the full post here and download the script here. […]

    Eswar Koneti said:
    November 25, 2010 at 4:34 am

    Here is another post which does the same Job usin softmif Tool instead VBS

    Trevor Sullivan said:
    November 18, 2011 at 6:34 am

    Nice script! Didn’t know anyone had written something like this :)


    Benoit NEVEU said:
    November 24, 2015 at 10:28 am

    U Rocks man !
    It’s perfect !

      N. Moseley responded:
      November 24, 2015 at 7:18 pm

      I’m glad it still works :-)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s