Hi,
Looking for some guidance on the below vbscript that i tried from the internet ,the vbscript that I am trying is a one which delets the currently configured SCCM boundaries from WMI and eventually from the console.
The vbscript below deletes all the boundaries successfully but I was looking at doing it in phases of say 100 boundaries at a time which can be inputted through a text file.
Kindly assist me to modify the script so that it reads a list of boundaries from an inpute text file and deletes only those instead of deleting all of the boundaries at one go.
Please find the script below which needs to be modified so that it reads a list from an input text file.
Thanks very much in advance,
With Kind Regards,
Susnata
'*****************************************************************************************************
' --- 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
Dim strBoundaryRead
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
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(".\BoundaryList.txt",1)
Do until objInputFile.AtEndOfStream
strBoundaryRead = objInputFile.ReadLine
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
Loop
objInputFile.Close
' 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
' *******************************************************************