'CreateAllDPsGroup.vbs 'Alan dot Kaplan at VA dot Gov 'Most of the interesting stuff comes from Niehous code, referenced below '//--------------------------------------------------------------------------- '// '// File: DPgroup.vbs '// '// Author: Michael Niehaus, Microsoft Consulting Services '// '// Input: none '// '// Return: none '// '// Purpose: This script adds the specified distribution point server or '// server share to the distribution point group coded below. '// '// This script does not follow the SMS server to SMS provider '// path, so you need to specify the SMS provider server name. '// '//--------------------------------------------------------------------------- dim wshShell Set wshShell = WScript.CreateObject("WScript.Shell") If (Not IsCScript()) Then 'If not CScript, re-run with cscript... dim strArgs, i For i = WScript.Arguments.Count -1 to 0 Step -1 strArgs = WScript.Arguments(i) & Space(1) & strArgs Next WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote & space(1) & strArgs, 1, true WScript.Quit '...and stop running as WScript End If iAdded = 0 message = "This script creates a DP group which excludes PXE shares." & vbcrlf & vbcrlf & _ "Enter the name of the site server upon which you want to create the Distribution Point Group" sServer = InputBox(message,"SCCM Server Name",wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")) If sServer = "" Then WScript.Quit sSiteCode = InputBox("Site code","Site",SCCM_Site(sServer)) If sSiteCode = "" Then WScript.Quit sGroup = InputBox("Enter the name of the DP Group","DP Group Name","All DPs") If sGroup = "" Then WScript.Quit ' Housekeeping On Error Resume Next Set services = GetObject("winmgmts://" & sServer & "/root/sms/site_" & sSiteCode) Set dpgClass = services.Get("SMS_DistributionPointGroup") If Err <> 0 Then WScript.Echo "Failed: " & Err.Description WScript.Quit End If Set dpGroup = services.Get("SMS_DistributionPointGroup.sGroupName='" & sGroup & "'") Set dpGroup = dpgClass.SpawnInstance_() dpGroup.sGroupName = sGroup dpGroup.arrNALPath = Array("") dpGroup.Put_ WScript.Echo "Created " & sGroup & " distribution point group." On Error Goto 0 strQuery = "Select * from SMS_SystemResourceList where RoleName = 'SMS Distribution Point' and ResourceType = 'Windows NT Server'" Set dps = services.ExecQuery(strQuery,,32) For each dp in dps iAdded = iAdded + 1 newNALPath = dpGroup.arrNALPath Redim Preserve newNALPath(UBound(dpGroup.arrNALPath)+1) newNALPath(UBound(newNALPath)) = dp.NALPath dpGroup.arrNALPath = newNALPath dpGroup.Put_ WScript.Echo " Added " & dp.ServerName & " to '" & sGroup & "' distribution point group." Next WScript.Echo CStr(iAdded) & " servers were added to '" & sGroup & "'" Function SCCM_Site(strComputer) On Error Resume Next Dim locator, wmi, obj Set locator = CreateObject("WbemScripting.SWbemLocator") Set wmi = locator.ConnectServer(strComputer, "root\sms") If Err <> 0 Then MsgBox "Failed to connect to " & strComputer, vbcritical + vbokonlyk,"Failed" WScript.Quit End If For Each obj In wmi.InstancesOf("__NAMESPACE") If InStr(obj.Name,"site") > 0 Then strNameSpace = replace(obj.Name,"site_","") End If Next SCCM_Site = strNameSpace On Error goto 0 End Function Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function