Count files in SCCM-inboxes – Version 2

A bit more complex version of the last script…

Requires a parameter for servername.

inboxcount.vbs

Option Explicit
Const cMinNofFiles = 1

Dim oFso, oArgs
Dim sPartOfPath, sServername, sSiteCode
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments

If oArgs.Count < 1 Then
        WScript.echo "ERROR: Missing argument!"
        WScript.Echo ""
        WScript.Echo "cscript.exe inboxCount.vbs SERVERNAME "
        WScript.Quit -1
End If
sServername = uCase(oArgs.Item(0))
If oArgs.Count-1 = 1 Then
        sPartOfPath = oArgs.Item(1)
Else
        sPartOfPath = ""
End If

sSiteCode = getSccmSiteCode(sServername)

WScript.Echo "=============================================================================="
WScript.Echo " SCCM Inbox Counter                            Rikard Ronnkvist / snowland.se"
WScript.Echo "------------------------------------------------------------------------------"
WScript.Echo "   Server: " & sServerName
WScript.Echo " SiteCode: " & sSiteCode
WScript.Echo "     Path: \\" & sServername & "\SMS_" & sSiteCode & "\inboxes"
WScript.Echo "------------------------------------------------------------------------------"
ListFolders "\\" & sServername & "\SMS_" & sSiteCode & "\inboxes", "\\" & sServername & "\SMS_" & sSiteCode & "\inboxes"
WScript.Echo "=============================================================================="

WScript.Quit

Function getSccmSiteCode(sServername)
        Dim oWMIService, oLocator, oSites, currentSite

        Set oLocator = CreateObject("WbemScripting.SWbemLocator")
        Set oWMIService = oLocator.ConnectServer(sServername, "root\sms", "", "")

        ' Now figure out the site code for this server.
        Set oSites = oWMIService.ExecQuery("SELECT SiteCode FROM SMS_ProviderLocation WHERE ProviderForLocalSite=true")

    For each currentSite in oSites
        getSccmSiteCode = Trim(currentSite.SiteCode)
        Exit Function
    Next
End Function

Sub ListFolders(sPath, sRoot)
        Dim oFolder, oFldr
        Set oFolder = oFSO.GetFolder(sPath)
        If (oFolder.Files.Count >= cMinNofFiles) AND (InStr(oFolder.Path, sPartOfPath) > 0) Then
                wscript.echo Left(oFolder.Files.Count & "        ", 6) & vbTab & Replace(uCase(oFolder.Path), uCase(sRoot), "")
        End If

        For Each oFldr In oFolder.SubFolders
                ListFolders oFldr.Path, sRoot
        Next
End Sub

MOM2005 Script to monitor nof files

A small script to create performance-data from the count of files in one folder.

'-------------------------------------------------------------------------------------
' Script to montior nof files in one folder
'
'                                         Rikard Ronnkvist / snowland.se / 2007-11-30
'-------------------------------------------------------------------------------------

Dim oFSO, oFolder, oFile, oPerfData
Dim folderName, perfData

Set oParams = ScriptContext.Parameters
folderName      = oParams.get("folderName")           ' "C:\Path"
Set oParams = Nothing

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(folderName)
Set oFile = oFolder.Files
perfData = oFile.Count
Set oFile = Nothing
Set oFolder = Nothing
Set oFSO = Nothing

Set oPerfData = ScriptContext.CreatePerfData
With oPerfData
        .ObjectName = cPerfObject
        .InstanceName = folderName
        .CounterName = cPerfCounter
        .Value = perfData
End With
ScriptContext.Submit oPerfData
Set oPerfData = Nothing