samedi 4 avril 2020

Covid19 - SCCM CB - VBScript to limit amount of VPN bandwidth for DP content

 

  To help you manage network bandwidth that is used for the content downloaded from your Distributions Points to clients in VPN including software update and applications, you can use the following VBScript to limit amount of bandwidth.

 

You can also schedule that in TaskScheduler for expl: Enable , Disable or modify the limit on the night, weekend,...

The <limits> element of the <site> element configures settings that limit the amount of bandwidth.

You can also configure the number of connections, or the connection time-out for client requests to a site but it is not recommanded and not supported by MS for SCCM.



If the <limits> element is configured in both the <siteDefaults> section and in the <site> section for a specific site, the configuration in the <site> section is used for that site.


 
 
 
The following configuration sample shows a Web site where the maximum bandwidth is set to 65,536 bytes per second.
  

VBScript

 
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")

Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If siteElementPos = -1 Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set limitsElement = siteElement.ChildElements.Item("limits")
limitsElement.Properties.Item("maxBandwidth").Value = 65536

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(valuesToMatch(iVal + 1)) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function