Getting a list of protected DPs in your hierarchy

I was recently asked if there was a way, via the SDK, to list out all your protected DPs and their configured boundaries. I found that this information is available using the SDK but not easily accessible. I have attached a script that is an example of how to do this. It lists out all DPs in your hierarchy, identifies whether they are protected, and then lists any configured boundaries.


 'Rslaten 03/2006
'Gets protected DPs
'Pass Central site server as first argument
'Needs more error checking added

WScript.Echo ""
WScript.Echo "GetProtectedDPs"
WScript.Echo "Usage: cscript.exe GetProtectedDPs.vbs <CenSiteServerName>"
WScript.Echo "Example: cscript.exe GetProtectedDPs.vbs myCentralSiteServer"
WScript.Echo ""

Dim oServices


Sub Main
    On Error Resume Next
    Dim sNameSpace, sSiteServer, sSiteCode, oLocator
    sSiteServer = WScript.Arguments(0)
    sNameSpace = GetSMSNameSpace(sSiteServer)
    sSiteCode = Right(sNameSpace, 3)
    Set oLocator = CreateObject("WbemScripting.SWbemLocator")
    'Connect to WMI
    Set oServices = oLocator.ConnectServer(sSiteServer, sNameSpace,,,,,128)
    If Err.number <> 0 Then
        WScript.Echo "Error connecting to " &sNameSpace& " on " &WScript.Arguments(0)& ": " &Err.Number
        Set oLocator = Nothing
        Set oServices = Nothing
    End If    
    'Refresh SCF
End Sub

'Queries DPs
Sub QueryDPs(sSiteCode)
    Dim collDP, oRes, sStart, aProps, oProp, aPropList, oPropList, oValue
    Set collDP = oServices.ExecQuery("select * from sms_sci_sysresuse where SiteCode = '"&sSiteCode&"'")
    For each oRes in collDP
        If oRes.RoleName = "SMS Distribution Point" Then
            sStart = InStr(oRes.NALPath,"=\\") + 3
            sFinish = InStr(oRes.NALPath,"]MSWNET") - 2
            sDP = mid(oRes.NALPath,sStart,sFinish-sStart)
            WScript.Stdout.Write sDP
            aProps = oRes.Props
            aPropList = oRes.PropLists
            For each oProp in aProps
                If oProp.PropertyName = "IsProtected" Then
                    If oProp.Value = 1 Then
                        WScript.Stdout.Write " (Protected)" & vbCrLf
                        WScript.Stdout.Write " (UnProtected)" & vbCrLf
                    End If
                End If
            For each oPropList in aPropList
                If oPropList.PropertyListName = "Protected Boundary" Then
                    For each oValue in oPropList.Values
                        Select Case oValue
                            Case "IP Subnets"
                                WScript.Stdout.Write vbTab & "Protected Boundary - IP Subnet: "
                            Case "AD Site Name"
                                WScript.Stdout.Write vbTab & "Protected Boundary - AD Site Name: "
                            Case "IP Ranges"
                                WScript.Stdout.Write vbTab & "Protected Boundary - IP Ranges: "
                            Case Else
                                WScript.Stdout.Write oValue & vbCrLf
                        End Select
                End If
        End If
    Set collDP = Nothing
End Sub

'Refreshes site control in WMI
Sub RefreshSCF(sSiteCode)
    On Error Resume Next
    Dim sQry, colSysRes
    sQry = "select * from SMS_SiteControlFile where FileType = 1 and SiteCode = '" &sSiteCode& "'"
    Set colSysRes = oServices.ExecQuery(sQry)
    If Err.number <> 0 Then
        WScript.Echo "Unable to query SMS Provider"
        WScript.Echo "Query: " & sQry
        WScript.Echo "Error = " & Err.number & " - " & Err.Description
    End If
    For each SCI in colSysRes
    Set colSysRes = Nothing
End Sub

'Gets SMS Namespace
Function GetSMSNameSpace(SiteServer)
    On Error Resume Next
    Dim colNameSpaceQuery, refitem, refWMI
    Set refWMI = GetObject("winMgmts:\\" &SiteServer&"\root\sms")
    If Err.number <> 0 Then
        WScript.Echo "Error connecting to SMS namespace on " &SiteServer
    End If
    Set colNameSpaceQuery = refWMI.ExecQuery("select * from SMS_ProviderLocation")
    For Each refitem in colNameSpaceQuery
        GetSMSNameSpace = refitem.NamespacePath
    Set colNameSpaceQuery = Nothing
    Set refitem = Nothing
    Set refWMI = Nothing
End Function