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!"
 


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…


Kill the task sequence window

There are a few blogposts about moving the task sequence status window.

An easy way is to simply kill it. :-)

A short VBScript-hack:

killProcess "TSprogressUI.exe"

Sub killProcess(sProcessToKill)
        Dim oProcesses, oProcess, oWMIService

        Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
        Set oProcesses = oWMIService.ExecQuery("Select * from Win32_Process Where Name = ‘" & sProcessToKill & "’")
        For Each oProcess in oProcesses
                oProcess.Terminate()
        Next   
End Sub
 

Some other ways:
http://blogs.technet.com/deploymentguys/archive/2008/10/09/placing-your-window-on-top-during-the-windowspe-stage.aspx

http://blogs.technet.com/deploymentguys/archive/2008/03/19/useful-script-number-2-move-the-task-sequence-window.aspx


Monitor COM+ Call Time

With a little help from Egilh you can monitor the Call Time on your COM-objects in MOM…

First, download and install the DLL on the server you want to monitor, then use this script:

‘————————————————————————————-
‘ Script to montior COM-obecjt call time

‘                                         Rikard Rönnkvist / snowland.se / 2008-09-16
‘————————————————————————————-

‘Get the com+ call times
Set oTracker = CreateObject("egilh.ComTracker")
sResult = oTracker.getStatistics()
       
‘Display call times
Set oDOM = CreateObject("MSXML2.DomDocument.3.0")
oDOM.loadXML (sResult)

For Each oNode In oDOM.selectNodes("/applications/application/classes/class")
        ‘ Create performance data
        Set oPerfData = ScriptContext.CreatePerfData
        With oPerfData
                .ObjectName = "COM-Objects"
                .InstanceName = oNode.selectSingleNode("progID").Text
                .CounterName = "CallTime"
                .Value = oNode.selectSingleNode("responseTime").Text
        End With
        ScriptContext.Submit oPerfData
        Set oPerfData = Nothing
Next
 


PXE Filter and Obsolete Machines

There is a small problem with the PXE filter and obsolete machines.

Today the PXE-Filter scans the SCCM-database for the machine and doesn’t bother if the machine is obsolete or not… and that might result in problems (The filter adds the obsolete machine to your collection).

Since the PXE-Filter is a VBScript… you can create a small hack…

Around row 150 you will find:

bFound = False
Set oClients = oSMS.ExecQuery(sQuery)
For each oClient in oClients
        bFound = true
        iResourceID = oClient.ResourceID
        PXE.LogTrace "Found existing machine " & oClient.NetbiosName & " with ResourceID = " & iResourceID
        sNetBiosName = oClient.NetbiosName
        Exit For
Next
 

Change that piece of code to:

bFound = False
Set oClients = oSMS.ExecQuery(sQuery)
For each oClient in oClients
        If oClient.Obsolete = 1 Then
                PXE.LogTrace "Found obsolete machine " & oClient.NetbiosName & ", skipping"
        Else
                bFound = True
                iResourceID = oClient.ResourceID
                PXE.LogTrace "Found existing machine " & oClient.NetbiosName & " with ResourceID = " & iResourceID
                sNetBiosName = oClient.NetbiosName
                Exit For
        End If
Next
 

That will result In a WDSServer.log (If you turn on tracing)

[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] Request from 10.26.64.240:67 Len:548
[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] About to run script
[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] Processing request from MAC address = 00:1E:0B:34:0F:E7, IP address = 0.0.0.0, UUID = E11832C1-58C0-DC11-BBDA-0B340FE7001E
[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] Found obsolete machine RIRO003, skipping
[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] Found existing machine RIRO003 with ResourceID = 112
[4332] 09:49:22: [WDSPXE] [Microsoft.BDD.PXEFilter] Added new membership rule to collection B0100012
 

SCCM Console Extensions

Some small notes and short (but powerful) example about SCCM Console Extensions…

Some good-to-have GUIDs
You find them all in adminconsole.xml

  • fa922e1a-6add-477f-b70e-9a164f3b11a2 - First-level collections
  • dbb315c3-1d8b-4e6a-a7b1-db8246890f59 - Subcollections
  • 7ba8bf44-2344-4035-bdb4-16630291dcf6 - Resource in collection
  • de41d5d8-3845-4e67-9657-0121f06f5e27 - Programs
  • a1ad0705-ce2d-4981-96f5-8f0faad47396 - Advertisments
  • 49696c48-9c3a-4d4a-bb38-473394700d43 - Site Systems

Some of the SUBs
You find them all in adminconsole.xml

  • ##SUB:__Server##
  • ##SUB:__Namespace##
  • ##SUB:Name##
  • ##SUB:PackageID##
  • ##SUB:ProgramName##
  • ##SUB:SiteCode##
  • ##SUB:SiteName##
  • ##SUB:NetworkOSPath##
  • ##SUB:AddressType##
  • ##SUB:Order##
  • ##SUB:value##
  • ##SUB:ItemName##

Example XML-file:
(Put it to “SCCM\AdminUI\XmlStorage\Extensions\Actions\fa922e1a-6add-477f-b70e-9a164f3b11a2\sccmExtensions.xml”)

Class="Executable" DisplayName="Show Params" MnemonicDisplayName="Show Params" Description = "Show Params">
        >

                >C:\sccmExtenstions.vbs>
                >##SUB:__Server## ##SUB:__Namespace## ##SUB:Name## ##SUB:PackageID## ##SUB:ProgramName## ##SUB:SiteCode## ##SUB:SiteName## ##SUB:NetworkOSPath## ##SUB:AddressType## ##SUB:Order## ##SUB:value## ##SUB:ItemName##>
        >
>
 

And the script to use
(Put this into C:\sccmExtensions.vbs)

sOut = ""
For i = 0 to WScript.Arguments.Count-1
        sOut = sOut & "Arg " & i+1 & " : " & Wscript.Arguments(i) & vbCrLf
Next
MsgBox sOut
 

Then, try to right-click a first level collection and select “Show Params”…

Tip
Greg Ramsy’s Console Extensions GUID Locator
;-)

Happy scripting! :-)


PXE Filter (v4.1.501)

Got a comment on another post from Thomas who was asking for a version of the PXE Filter that works.

I have used this one on a few installations.

You need to configure:
sProviderServer if you have the PXE point on another server
sSiteCode for your site
sCollection to the collection which you advertise your deployment task sequence

What the PXEFilter does is (in general):

  • Check if the machine exist, and if not adds it to the SCCM.
  • Checks if the machine is member of a specific collection (sCollection) and if not adds it to the collection (Direct member)
  • Waits until the machine can see the advertisment (A maximum of 30 seconds)

PXEFilter.vbs v4.1.501 (Download VBS)

‘ //***************************************************************************
‘ // ***** Script Header *****
‘ //
‘ // Solution:  Microsoft Deployment Toolkit
‘ // File:      PXEFilter.vbs
‘ //
‘ // Purpose:   Decide what needs to be done for each PXE requests received
‘ //            by WDS.  If not present in the ConfigMgr database, add it.
‘ //
‘ // Usage:     (loaded automatically by Microsoft.BDD.PXEFilter DLL)
‘ //
‘ // Microsoft Solution Version:  4.1.501
‘ // Microsoft Script Version:    4.1.501
‘ // Customer Build Version:      1.0.0
‘ // Customer Script Version:     1.0.0
‘ //
‘ // Microsoft History:
‘ // 4.0.501 MTN  02/19/2008  Added header, additional logging, advertisement
‘ //                          verification for every request.
‘ //
‘ // Customer History:
‘ //
‘ // ***** End Header *****
‘ //***************************************************************************

‘//—————————————————————————-
‘//
‘//  Set global variables, used by the ZTIProcess function below.  (Note that
‘//  any changes to this script will require restarting the WDS service, since
‘//  the script is only loaded once and kept in memory as long as the service
‘//  is running.)
‘//
‘//  If ConfigMgr is running on the same server as WDS, the sProviderServer
‘//  value can be left blank and the sUsername and sPassword values must be
‘//  blank.
‘//—————————————————————————-

Option Explicit

Dim sProviderServer
Dim sSiteCode
Dim sNamespace
Dim sUsername
Dim sPassword
Dim sCollection

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

‘//—————————————————————————-
‘//  Main routine
‘//—————————————————————————-

ZTIProcess

Function ZTIProcess

        Dim sMacAddress
        Dim sIPAddress
        Dim sUUID
        Dim sNetBiosName
        Dim oLocator
        Dim oSMS
        Dim sQuery
        Dim bFound
        Dim iResourceID
        Dim re
        Dim oSite
        Dim oParams
        Dim oResult
        Dim oLastError
        Dim oClients
        Dim oClient
        Dim oCollection
        Dim oNewRule
        Dim oAdvertisement
        Dim bTrying
        Dim sAdvert
        Dim i

        ‘ Initialization

        sMacAddress = PXE.MacAddress
        sIPAddress = PXE.IPAddress
        sUUID = PXE.UUID

        Set re = New RegExp
        re.Pattern = ":"
        re.Global = true
        sNetBiosName = "MAC" & re.Replace(sMacAddress, "")

        ‘ Clear invalid UUID values

        If sUUID = "00000000-0000-0000-0000-000000000000" or sUUID = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" then
                sUUID = ""
        End if

        ‘ Log details

        PXE.LogTrace "Processing request from MAC address = " & sMacAddress & ", IP address = " & sIPAddress & ", UUID = " & sUUID

        ‘//—————————————————————————-
        ‘//  Filter requests.  This may need to be customized if you only want some
        ‘//  network segments to be supported.
        ‘//—————————————————————————-

        ‘ Ignore ConfigMgr "ping" requests

        If PXE.IPAddress = "127.0.0.1" or PXE.MacAddress = "FF:FF:FF:FF:FF:FF" then
                PXE.LogTrace "Ignoring ConfigMgr ping request"
                Exit Function
        End if

        ‘//—————————————————————————-
        ‘//  Verify the computer is known to ConfigMgr
        ‘//—————————————————————————-

        ‘ Connect to the SMS provider

        Set oLocator = CreateObject("WbemScripting.SWbemLocator")
        Set oSMS = oLocator.ConnectServer(sProviderServer, sNamespace, sUsername, sPassword)

        ‘ Build the query

        sQuery = "SELECT * FROM SMS_R_System WHERE MacAddresses = ‘" & sMacAddress & "’"
        If sUUID <> "" then
                sQuery = sQuery & " OR SMBIOSGUID = ‘" & sUUID & "’"
        End if

        ‘ Process the query

        bFound = False
        Set oClients = oSMS.ExecQuery(sQuery)
        For each oClient in oClients
                bFound = true
                iResourceID = oClient.ResourceID
                PXE.LogTrace "Found existing machine " & oClient.NetbiosName & " with ResourceID = " & iResourceID
                sNetBiosName = oClient.NetbiosName
                Exit For
        Next

        ‘//—————————————————————————-
        ‘//  If necessary, add the computer to the ConfigMgr database
        ‘//—————————————————————————-

        If not bFound then

                PXE.LogTrace "Could not find machine with MAC address ‘" & sMacAddress & "’ or SMBIOS UUID ‘" & sUUID & "’."

                ‘ Add the computer

                Set oSite = oSMS.Get("SMS_Site")
                Set oParams = oSite.Methods_.Item("ImportMachineEntry").inParameters.SpawnInstance_()
                oParams.NetbiosName = sNetBiosName
                oParams.SMBIOSGUID = sUUID
                oParams.MACAddress = sMacAddress
                oParams.OverwriteExistingRecord = false

                On Error Resume Next
                Set oResult = oSite.ExecMethod_("ImportMachineEntry", oParams)
                If Err then
                        PXE.LogTrace "Error importing machine entry: " & Err.Description & " (" & Err.Number & ")"
                        Set oLastError = CreateObject("WbemScripting.SWbemLastError")
                        PXE.LogTrace "Last WMI error: " & oLastError.Description
                        Exit Function
                End if
                On Error Goto 0

                iResourceID = oResult.ResourceID
                PXE.LogTrace "Added new machine with ResourceID = " & iResourceID

        End if

        ‘//—————————————————————————-
        ‘//  Check if the computer is a member of the specified collection
        ‘//—————————————————————————-

        If bFound then

                ‘ Build the query

                sQuery = "SELECT * FROM SMS_CM_RES_COLL_" & sCollection & " WHERE ResourceID = " & iResourceId

                ‘ Process the query

                bFound = False
                Set oClients = oSMS.ExecQuery(sQuery)
                For each oClient in oClients
                        bFound = true
                        PXE.LogTrace "Machine is already in collection " & sCollection
                        Exit For
                Next

        End If

        ‘//—————————————————————————-
        ‘//  If necessary, add the computer to the specified collection
        ‘//—————————————————————————-

        If not bFound then

                ‘ Add the computer to the specified collection

                On Error Resume Next
                Set oCollection = oSMS.Get("SMS_Collection.CollectionID=’" & sCollection & "’")
                If Err then
                        PXE.LogTrace "Error retrieving collection " & sCollection & ": " & Err.Description & " (" & Err.Number & ")"
                        Set oLastError = CreateObject("WbemScripting.SWbemLastError")
                        PXE.LogTrace "Last WMI error: " & oLastError.Description
                        Exit Function
                End if
                On Error Goto 0

       
                Set oNewRule = oSMS.Get("SMS_CollectionRuleDirect").SpawnInstance_()
                oNewRule.ResourceClassName = "SMS_R_System"
                oNewRule.RuleName = sNetBiosName
                oNewRule.ResourceID = iResourceID

                On Error Resume Next
                oCollection.AddMembershipRule oNewRule
                If Err then
                        PXE.LogTrace "Error adding membership rule to " & sCollection & ": " & Err.Description & " (" & Err.Number & ")"
                        Set oLastError = CreateObject("WbemScripting.SWbemLastError")
                        PXE.LogTrace "Last WMI error: " & oLastError.Description
                        Exit Function
                End if
                On Error Goto 0
                PXE.LogTrace "Added new membership rule to collection " & sCollection

        End if

        ‘//—————————————————————————-
        ‘//  Wait until an advertisement is seen.
        ‘//—————————————————————————-

        ‘ Check for the advertisements

        Set oAdvertisement = oSMS.Get("SMS_Advertisement")
        i = 0
        bTrying = True
        Do While bTrying

                Set oParams = oAdvertisement.Methods_("GetAdvertisements").inParameters.SpawnInstance_()
                oParams.ResourceID = iResourceID

                Set oResult = oAdvertisement.ExecMethod_("GetAdvertisements", oParams)
                For each sAdvert in oResult.AdvertisementIDs
                        PXE.LogTrace "Found advertisement " & sAdvert
                        bTrying = False
                Next

                i = i + 1
                If bTrying and i > 10 then
                        PXE.LogTrace "Giving up after 30 seconds of checking for new advertisements."
                        bTrying = False
                End if

                PXE.Sleep 3000

        Loop

        PXE.LogTrace "Exiting PXEFilter.vbs"

End Function
 


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
 


SCOM Demo script

OK, so I did some more research and scripting last evning…

Here is a script that puts out some random perfomance data between the parameters to the script.

In the perfomance mapper, set Value to $Data/Property[@Name='Perfdata']$, and don’t forget the parameters.

‘————————————————————————————-
‘ Script to write random perf-data

‘                                         Rikard Rönnkvist / snowland.se / 2007-10-24
‘————————————————————————————-
‘ — Set up variables and objects
Option Explicit
Dim iMinRnd, iMaxRnd, perfData
Dim oArgs, oAPI, oBag

‘ — Get parameters
Set oArgs = WScript.Arguments
iMinRnd = Int(oArgs.Item(0))
iMaxRnd = Int(oArgs.Item(1))
Set oArgs = Nothing

‘ — Generate random number
Randomize
perfData = Int((iMaxRnd - iMinRnd + 1) * Rnd + iMinRnd)

‘ — Create properies in SCOM
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

oBag.AddValue "minValue", iMinRnd
oBag.AddValue "maxValue", iMaxRnd
oBag.AddValue "Perfdata", perfData
oAPI.AddItem(oBag)
oAPI.ReturnItems

Set oAPI = Nothing
Set oBag = Nothing

 

I did use “500 1000″ as a paramreter and got this nice demo-view of performance:
Demodata

Now, its time to play with alerts and baselining that data…


Next Page »