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.

'==========================================================================
' NAME   : Get_BADMIFS
' AUTHOR : Nick Moseley, https://t3chn1ck.wordpress.com
' 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 & "\ddm.box\BAD_DDRS")
Set cBadDDRFiles = oBadDDRFolder.Files
Set oBadMIFFolder = oFSO.GetFolder(sSMSInbox & "\auth\dataldr.box\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
            Else
                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
    Loop
    oMIFFile.Close
	
    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
    Loop	
    oMIFFile.Close
Next

oExcel.Range("A1:E1").Select
oExcel.Selection.Interior.ColorIndex = 19
oExcel.Selection.Font.ColorIndex = 11
oExcel.Selection.Font.Bold = True
oExcel.Cells.EntireColumn.AutoFit
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 – http://myitforum.com/myitforumwp/2011/11/07/badmif-processing-when-a-client-doesnt-report-hardware-inventory/

Advertisements

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 http://eskonr.wordpress.com/2010/01/11/inventory-data-loader-issues-in-sccm-inboxes/

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

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

    Cheers,
    Trevor

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s