Semiautomatic deletion/creation/whatever

Ok.. you need to automate a klick-klick-klick-procedure… SendKeys can do the trick.

A big warning: This might be dangerous, if the script goes berserk… it might do whatever deletion/creation/manipulation in the wrong area…

Set oShell = CreateObject("WScript.Shell")

oShell.AppActivate "Configuration Manager Console"
WScript.Sleep 500

For i = 1 To 10
        oShell.SendKeys "{DOWN}"
        WScript.Sleep 250
        oShell.SendKeys "{DELETE}"
        WScript.Sleep 250
        oShell.SendKeys "{ENTER}"

        WScript.Sleep 2000
Next
MsgBox "Done!"

Clients missing inventory

I’m trying to figure out why some clients are missing the inventory in add/remove programs…
So I made a nice little collection with a query that only shows clients missing the inventory.

SELECT *
FROM SMS_R_System
WHERE
        SMS_R_System.ResourceId NOT IN (SELECT ResourceID FROM SMS_G_System_ADD_REMOVE_PROGRAMS)
        AND Client = 1

Check WMI on SCCM-server

If you have problems with WMI on a SCCM server you have will have loads of strange things happening.

Wrote a small VBScript to check WMI… here it is:

Set oLocator = CreateObject("WbemScripting.SWbemLocator")

' --- Checking local WMI
WScript.Echo " Connect: root\CIMV2"
Set oWMIService = oLocator.ConnectServer(".", "root\CIMV2", "", "")

WScript.Echo "   Query: Select UUID from Win32_ComputerSystemProduct"
Set oWmiQuery = oWMIService.ExecQuery("Select UUID from Win32_ComputerSystemProduct")
For Each oUuid In oWmiQuery
        sUuid = oUuid.UUID
        WScript.Echo "Response: " & sUuid
        Exit For
Next
WScript.Echo ""

' --- Figure out site code
WScript.Echo " Connect: root\sms"
Set oWMIService = oLocator.ConnectServer(".", "root\sms", "", "")

WScript.Echo "   Query: SELECT SiteCode FROM SMS_ProviderLocation WHERE ProviderForLocalSite=true"
Set oWmiQuery = oWMIService.ExecQuery("SELECT SiteCode FROM SMS_ProviderLocation WHERE ProviderForLocalSite=true")
For each currentSite in oWmiQuery
        sSccmSiteCode = currentSite.SiteCode
        WScript.Echo "Response: " & sSccmSiteCode
        Exit For
Next
WScript.Echo ""

' --- Connect to site
WScript.Echo " Connect: root\sms\site_" & sSccmSiteCode
Set oWMIService = oLocator.ConnectServer(".", "root\sms\site_" & sSccmSiteCode, "", "")

WScript.Echo "   Query: Select Name, ResourceID FROM SMS_R_System WHERE SmbiosGuid = '" & sUuid & "'"
Set oWmiQuery = oWMIService.ExecQuery("Select ResourceID FROM SMS_R_System WHERE SmbiosGuid = '" & sUuid & "'")
For each myMachine in oWmiQuery
        WScript.Echo "Response: " & myMachine.ResourceID
        Exit For
Next

Or download here: wmiTester.vbs


Count make/model from SCCM

If you are about to certify machines to SCCM and dont know what kind of machines there are.

Here is a query to show you make and model:

SELECT
        Manufacturer0 AS Manufacturer,
        Model0 AS Model,
        COUNT (Model0) AS Count
FROM v_GS_COMPUTER_SYSTEM
GROUP BY Model0, Manufacturer0
ORDER BY Manufacturer0, Model0

Just create a report and paste the query…


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

Read PXEFilter settings from registry

First off… populate HKEY_LOCAL_MACHINE\SOFTWARE\snowland\PXEFilter\ with some strings (ProviderServer, SiteCode, Username, Password, Collection).
Second, edit the pxefilter.vbs and change the following lines:

sProviderServer = ""
sSiteCode = "ABC"
sNamespace = "root\sms\site_" & sSiteCode
sUsername = ""
sPassword = ""
sCollection = "ABC00004"   'This must be a collection ID, not a collection name

To this new code:

Function readRegistry(sRegKey, sDefaultValue)
        Dim oWshShell, sVal
        Set oWshShell = CreateObject("WScript.Shell")
        On Error Resume Next
        sVal = oWshShell.RegRead(sRegKey)
        If Err.Number <> 0 Then
                readRegistry = sDefaultValue
        Else
                readRegistry = sVal
        End If
        On Error Goto 0
        Set oWshShell = Nothing
End Function

Const cKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\snowland\PXEFilter\"
sProviderServer = readRegistry(cKeyPath & "ProviderServer",  "")
sSiteCode = readRegistry(cKeyPath & "SiteCode",              "ABC")
sUsername = readRegistry(cKeyPath & "Username",               "")
sPassword = readRegistry(cKeyPath & "Password",               "")
sCollection = readRegistry(cKeyPath & "Collection",           "ABC00004")
sNamespace = "root\sms\site_" & sSiteCode

Now, on startup the filter will read from HKLM to get the settings, if there is an error when reading (no value, no rights) the script will default to “ABC” for sSiteCode and so on…