Script to delete boundaries

Does anyone know if there is a SCCM VBS script which can remove the boundaries ?

I want to remove all boundaries before I create the new ones because else they will be added twice.

PS. in de GUI they appears one, but in the site control file they are listen more then once.

October 6th, 2010 6:37pm

Here's the core subroutine for one I created and used in the past. It was 2004 when I last edited this one, but it should still work for ConfigMgr 2007. As always with scripts, be sure to test it thoroughly in your test environment first.

The premise of this subroutine is that you've built a list of boundaries you want in the boundaries array - that would be all of them without the ones you want removed, in this case. It also assumes you're only using IP subnets as boundaries, but it would be easy to adapt it to handle the other kinds of boundaries.

The SDK has more background on scripting site control file changes.

 Set WbemContext=CreateObject("WbemScripting.SWbemNamedValueSet")
 WbemContext.Add "SessionHandle", WbemServices.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle
 WbemServices.ExecMethod "SMS_SiteControlFile.Filetype=2,Sitecode='" & Site & "'", "Refresh", , , WbemContext
 'WbemServices.ExecMethod "SMS_SiteControlFile.Sitecode='" & Site & "'", "RefreshSCF", , , WbemContext

 Set WbemInst = WbemServices.Get("SMS_SCI_SiteAssignment.Filetype=2,Itemtype='Site Assignment',Sitecode='" & Site & "',ItemName='Site Assignment'", , WbemContext)

 'Retrieve the boundary details
 proparray1 = WbemInst.AssignDetails
 proparray2 = WbemInst.AssignTypes

 duplicates = 0 : added = 0

 for i=0 to numboundaries-1

  boundary = boundaries(i)
  boundary_type = "IP Subnets"

  if boundary<>"" then 'as it would be if it was found to be a duplicate

   onemore = ubound(proparray1) + 1
   redim preserve proparray1( onemore )
   redim preserve proparray2( onemore )
 
   proparray1( onemore ) = boundary
   proparray2( onemore ) = boundary_type

   added = added + 1

  else
   duplicates = duplicates + 1
  end if

 Next

 WbemInst.AssignDetails = proparray1
 WbemInst.AssignTypes   = proparray2
 WbemInst.Put_ , WbemContext
    
 'WbemServices.ExecMethod "SMS_SiteControlFile.Sitecode=""" & Site & """", "CommitSCF", , , WbemContext
 WbemServices.ExecMethod "SMS_SiteControlFile.Filetype=2,Sitecode=""" & Site & """", "Commit", , , WbemContext
 WbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle WbemContext.Item("SessionHandle").Value

 

Free Windows Admin Tool Kit Click here and download it now
October 12th, 2010 9:59pm

I created it myself and it works perfectly:

' --- Global Variables ---
Dim gsSiteCode			' The site code of the site
Dim gsProvider			' The machine with the provider
Dim goWMIConnection		' SWbemServices connection to the SMS provider
Dim goWMIContext		' Context for WMI Calls
Dim gsSessionHandle		' Session Handle of the SCF we're manipulating
Dim filename
Dim strReadLine

Set objWS = CreateObject("Wscript.Shell")

gsServer = ""			' Name of the Site Server machine
gsUser = ""			' Admin account on the Site Server
gsPass = ""			' Password for the admin account

PrimarySiteCode = "xxx" '<-- fill in the primary site code

If WScript.Arguments.Count = 1 Then
 SiteCode = WScript.Arguments(0)
Else
 if SiteCode="" then
 SiteCode = InputBox("Enter the site from which to remove the boundaries","Site Code Input")
 end if
 if SiteCode="" then
 msgbox "error no sitecode"
 wscript.quit
 end if
End If

' Establish a connection to WMI
Connect PrimarySiteCode

' Get a new SCF session handle
gsSessionHandle = GetSessionHandle()
	
' Build a context object
BuildWMIContext gsSessionHandle

sRelPath = "SMS_SCI_RoamingBoundary.FileType=1,Itemtype='Roaming Boundary',SiteCode='" & SiteCode & "',ItemName='Roaming Boundary'"
Set WbemInst = goWMIConnection.Get(sRelPath,, goWMIContext)
	
'dim new array
redim newproparray1(0)
redim newproparray2(0)
redim newproparray3(0)
redim newproparray4(0)

'create new empty array
newproparray1(0) = ""
newproparray2(0) = ""
newproparray3(0) = ""
newproparray4(0) = ""

'write new empty array to values
WbemInst.Details  = newproparray1
WbemInst.Types  = newproparray2
WbemInst.DisplayNames = newproparray3
WbemInst.Flags  = newproparray4

WbemInst.Put_ , goWMIContext
	
' Commit the SCF changes
CommitSCF SiteCode
	
' Release the session handle
ReleaseSessionHandle gsSessionHandle

objWS.Popup "OK",300,"Message",64

'**********************************************************************************
'**********************************************************************************
'**********************************************************************************


' *******************************************************************
' Connect() - This sub makes a connection to the SMS Provider
' *******************************************************************

Sub Connect(strSiteCode)

	' Create a WMI Locator
	Dim oLocator
	Set oLocator = CreateObject("WbemScripting.SWbemLocator")

	' Trap the WMI Exceptions
	On Error Resume Next
		
	' Connect to the "root\sms" namespace on the site server
	Set goWMIConnection = oLocator.ConnectServer(gsServer, "root\sms")
	If Err.number <> 0 Then
		MsgBox "Failed to connect to the ""\\" & gsServer & "\root\sms"" namespace." & vbCrLf & "WMI ERROR: " & Err.Description & " (" & Err.Number & ") ", vbCritical, "Error"
		WScript.Quit()
	End if 
	
if strSiteCode = "" Then
	' Query for the SMS_ProviderLocator instance for this site server
	Dim osQueryResults
	Set osQueryResults = goWMIConnection.ExecQuery("SELECT * FROM SMS_ProviderLocation WHERE ProviderForLocalSite=""TRUE""")
	
	' Loop through the results
	Dim oInst
	For Each oInst in osQueryResults
		
		' Get the Provider Machine & the Site Code
		gsProvider = oInst.Machine
		PrimarySiteCode = oInst.SiteCode
		Exit For
	Next
else
 PrimarySiteCode = strSiteCode
end if
	' Make sure we didn't have any errors
	If Err.number <> 0 Then
		MsgBox "Failed to find the provider for the site """ & gsServer & """." & vbCrLf & "WMI ERROR: " & Err.Description & " (" & Err.Number & ") ", vbCritical, "Error"
		WScript.Quit()
	End if 
	
	' Connect to the "root\sms\site_ABC" namespace on the provider machine
	Set goWMIConnection = oLocator.ConnectServer(gsProvider, "root\sms\site_" & PrimarySiteCode, gsUser, gsPass)
	If Err.number <> 0 Then
		MsgBox "Failed to connect to the ""\\" & gsProvider & "\root\sms\site_" & PrimarySiteCode & """ namespace." & vbCrLf & "WMI ERROR: " & Err.Description & " (" & Err.Number & ") ", vbCritical, "Error"
		WScript.Quit()
	End if 

	' Turn exception handling back on
	On Error Goto 0
	
End Sub

' *******************************************************************
' BuildWMIContext() - This sub will create a new WMI Context object
' *******************************************************************

Sub BuildWMIContext(sSessionHandle)

	' Create a new context object
	Set goWMIContext = CreateObject("WbemScripting.SWbemNamedValueSet")
	
	' Add the session handle to the context object
	goWMIContext.Add "SessionHandle", sSessionHandle
	
End Sub

' *******************************************************************
' GetSessionHandle() - This function gets a new session handle for SCF manipulation
' *******************************************************************

Function GetSessionHandle()

 ' Get the SMS_SiteControlFile object
 Dim oSCFClass
 Set oSCFClass = goWMIConnection.Get("SMS_SiteControlFile")
 
 ' Call the GetSessionHandle method
 Dim oOutParams
 Set oOutParams = oSCFClass.ExecMethod_("GetSessionHandle")
 
 ' Get the session handle from the results
 GetSessionHandle = oOutParams.SessionHandle
 
End Function

' *******************************************************************
' ReleaseSessionHandle() - This function releases an existing session handle
' *******************************************************************

Sub ReleaseSessionHandle(sSessionHandle)

	' Get the SMS_SiteControlFile object
	Dim oSCFClass
	Set oSCFClass = goWMIConnection.Get("SMS_SiteControlFile")
	
	' Call the ReleaseSessionHandle method
	oSCFClass.ReleaseSessionHandle(sSessionHandle)
	
End Sub

' *******************************************************************
' RefreshSCF() - This function will refresh a specific SCF
' *******************************************************************

Sub RefreshSCF(sSiteCode)

	' Get the SMS_SiteControlFile object
	Dim oSCFClass
	Set oSCFClass = goWMIConnection.Get("SMS_SiteControlFile")
	
	' Get the InParams for the method
	Dim oInParams
	set oInParams = oSCFClass.Methods_("RefreshSCF").InParameters.Clone_
	
	' Set the InParams for the method
	oInParams.Properties_("SiteCode").Value = sSiteCode
	
	' Call the RefreshSCF method
	oSCFClass.ExecMethod_ "RefreshSCF", oInParams, , goWMIContext
	
End Sub

' *******************************************************************
' CommitSCF() - This function will commit any changes to a specific SCF
' *******************************************************************

Sub CommitSCF(sSiteCode)

	' Get the SMS_SiteControlFile object
	Dim oSCFClass
	Set oSCFClass = goWMIConnection.Get("SMS_SiteControlFile")
	
	' Get the InParams for the method
	Dim oInParams
	set oInParams = oSCFClass.Methods_("CommitSCF").InParameters.Clone_
	
	' Set the InParams for the method
	oInParams.Properties_("SiteCode").Value = sSiteCode
	
	' Call the CommitSCF method
	oSCFClass.ExecMethod_ "CommitSCF", oInParams, , goWMIContext
	
End Sub

' *******************************************************************



October 14th, 2010 9:49am

Hi,

Thank you very much for the script,it's working absolutely fine,and it replaces with the blank array that you mentioned,but i wanted to get an advice from you as to how I can have it to read a text file as an input with a list of boundaries which it would only delete instead of deleting all of them so that it would be possible to do it in phases.

Thanks,

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 6:43am

Please....any inputs or suggestions regarding this.

Thanks

July 8th, 2013 7:51am

Please....any inputs or suggestions regarding this.


What you are asking for is NOT a CM07 issue, it is a VBscript question. I suggest posting your question within one of the scripting forums.
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2013 8:15am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics