The Office Communication Server (OCS) 2007 Quality of Experience Monitoring Server Administration Tool (MMC) does not support associating OCS 2007 Mediation Severs with an OCS 2007 R2 Pool to receive QoE reports, so this script provides a way to accomplish this task. This script can also be used to associate OCS 2007 R2 Mediation Servers with an OCS 2007 R2 Pool to receive QoE reports, but that can also be achieved using the OCS 2007 R2 Administration tool (MMC). After a Mediation Server is associated with a Pool, QoE reports from that Mediation Server will be delivered to the Monitoring Server that is associated with that OCS 2007 R2 Pool.

Usage:

cscript Associate.vbs [-P PoolFQDN] [-M MediationServerFQDN] [-LP] [-LM] [-W]

Where:

-P: poolFQDN: Specify OCS 2007 R2 Pool which the Mediation Server will be associated with

-M: mediationServerFQDN: Specify Mediation Server instance which will be associated to the Pool if * is specified as the Mediation Server FQDN and option -W is specified, all OCS 2007 or OCS 2007 R2 Mediation Servers will be associated to the Pool

-W: Allow wildcarding on mediation server

-LP: List all OCS 2007 R2 Pools

-LM: List all OCS 2007 or OCS 2007 R2 Mediation Servers

Notes: (1) All parameters are case insensitive. (2) The script must be run on a machine that has the OCS Admin Tools deployed. Examples:

List all OCS 2007 R2 Pools:

cscript Associate.vbs -LP

List all OCS 2007 or OCS 2007 R2 Mediation Servers:

cscript Associate.vbs -LM

Associate Mediation Server whose FQDN is medsrv.myorg.com with Pool whose FQDN is pool.myorg.com:

cscript Associate.vbs -P pool.myorg.com -M medsrv.myorg.com

This script contributed by Clark Chen of Microsoft.

Visual Basic
Edit|Remove
' Associate.vbs
' 
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 
' OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
' FITNESS FOR A PARTICULAR PURPOSE.
'
' Copyright (c) Microsoft Corporation. All rights reserved
'
' This script is not supported under any Microsoft standard support program or service. 
' The script is provided AS IS without warranty of any kind. Microsoft further disclaims all
' implied warranties including, without limitation, any implied warranties of merchantability
' or of fitness for a particular purpose. The entire risk arising out of the use or performance
' of the scripts and documentation remains with you. In no event shall Microsoft, its authors,
' or anyone else involved in the creation, production, or delivery of the script be liable for 
' any damages whatsoever (including, without limitation, damages for loss of business profits, 
' business interruption, loss of business information, or other pecuniary loss) arising out of 
' the use of or inability to use the script or documentation, even if Microsoft has been advised 
' of the possibility of such damages.

Const wbemChangeFlagUpdateOnly = 1
WMIComputer = "."
WMINameSpace = "root\cimv2"
TustedServiceClass = "MSFT_SIPTrustedServiceSetting"
PoolSettingClass = "MSFT_SIPPoolSetting"
MediationServerSetting = "MSFT_SIPMediationServerSetting"
QoSServerType = "QoS"
MSServerType = "MediationServer"
Version = "Version:"
Association = "Associated with:"

'Config - version 3: OCS 2007, version 4: OCS 2007 R2
QoSVersion = "4"
'MSVersion = "3" or MSVersion = "4" indicated in code
fDisableWideMatch = False

'Error msg
strMissingParametersForAssociate = "Missing parameters for option "
strInvalidOptions = "Invalid options "
strNoInstanceFound = "No Instance could be found. Make sure you are running the tool on a machine with the OCS 2007 or OCS 2007 R2 Admin Tools deployed"
strNoMediationServerFound = "No Mediation Server could be found, make sure you are running the tool on a machine with the OCS 2007 or OCS 2007 R2 Admin Tools deployed."
strPoolNotExists = " does not exist or is not a OCS 2007 R2 Pool. The association attempt failed."
strMediationServerNotExists = " does not exist or is not a OCS 2007 or OCS 2007 R2 Mediation Server. The association attempt failed."
strPoolOrMSMissed = "If either -P or -M are used, then both are required."

'internal variables
Dim WMIClass, QoSServerDN

'Command options
Dim fUpdateAssociation, fListPool, fListMediationServer
Dim fShowDetailInfo

'Command option parameters
Dim PoolFQDN, MediationServerFQDN

'Default options
fUpdateAssociation = False
fListPool = False
fListMediationServer = False

Main

Function CheckError(errInfo)
    If Err <> 0 Then
        WScript.Echo errInfo
        WScript.Echo "Err number: "&Err.Number
        WScript.Echo "Err description: "&Err.Description
        WScript.Quit(Err.number)
    End If

End Function

Function IsEmptyString(str)
    If IsNull(str) Or IsEmpty(str) Or str = "" Then
        IsEmptyString = True
    Else
        IsEmptyString = False
    End If
End Function

Function ListInstances(className)
    On Error resume next
    
    If IsEmptyString(className) Then
        WScript.Echo "className is empty in ListInstances"
        WScript.Quit(1)
    End If
    
    set trustedServiceSet = WMIClass.InstancesOf(TustedServiceClass)
    CheckError("Instance does not exist")
    
    If IsNull(trustedServiceSet) or trustedServiceSet.Count <= 0 Then
        WScript.Echo strNoInstanceFound
        WScript.Quit(1)
    End If

    Select Case className
        Case PoolSettingClass
            WScript.Echo "OCS 2007 R2 Pools:"
        Case MediationServerSetting
            WScript.Echo "OCS 2007 or OCS 2007 R2 Mediation Servers:"
    End Select
    
    For Each objInstance In trustedServiceSet
        If IsNull(objInstance) Then
            'WScript.Echo "found null instance, skip"
            Continue
        End If
   
        If IsNull(objInstance.Type) or IsNull(objInstance.Version) Then
            'WScript.Echo "Specific field is null, skip"
            Continue
        End If

        Select Case className
            Case PoolSettingClass
                If Ucase(objInstance.Type) = Ucase(QoSServerType) and CStr(objInstance.Version) = QoSVersion Then
                    WScript.Echo objInstance.FQDN
                End If
            Case MediationServerSetting
                If Ucase(objInstance.Type) = Ucase(MSServerType) Then
                    If CStr(objInstance.Version) = "3" Then
                        WScript.Echo objInstance.FQDN & "(OCS 2007)"
                        WScript.Echo "    " & Association & GetQoSFQDN(GetAsscoiatedQoSDN(objInstance.FQDN))
                    End If
                    If CStr(objInstance.Version) = "4" Then
                        WScript.Echo objInstance.FQDN & "(OCS 2007 R2)"
                        WScript.Echo "    " & Association & GetQoSFQDN(GetAsscoiatedQoSDN(objInstance.FQDN))
                    End If
                End If
        End Select

    Next
    
    WScript.Echo ""
    
End Function

Function GetAsscoiatedQoSDN(strFqdn)
    ON Error resume next
    
    'List trusted service instances
    set trustedServiceSet = WMIClass.InstancesOf(MediationServerSetting)
    If IsNull(trustedServiceSet) or trustedServiceSet.Count <= 0 Then
        WScript.Echo strNoInstanceFound
        WScript.Quit(1)
    End If
    
    For Each objInstance In trustedServiceSet
        If UCase(objInstance.FQDN) = UCase(strFqdn) Then
            GetAsscoiatedQoSDN = objInstance.TrustedQoSServer
            Exit Function
        End IF
    Next

    GetAsscoiatedQoSDN = null
End Function

Function GetQoSFQDN(ServerDN)
    ON Error resume next
    
    'List trusted service instances
    set trustedServiceSet = WMIClass.InstancesOf(TustedServiceClass)
    If IsNull(trustedServiceSet) or trustedServiceSet.Count <= 0 Then
        WScript.Echo strNoInstanceFound
        WScript.Quit(1)
    End If
    
    For Each objInstance In trustedServiceSet
        If UCase(objInstance.TrustedServiceDN) = UCase(ServerDN) Then
            GetQoSFQDN = objInstance.FQDN
            Exit Function
        End IF
    Next

    GetQoSFQDN = null
End Function

Function CheckMSVersion(strFqdn)
    ON Error resume next
    
    'List trusted service instances
    set trustedServiceSet = WMIClass.InstancesOf(TustedServiceClass)
    If IsNull(trustedServiceSet) or trustedServiceSet.Count <= 0 Then
        WScript.Echo strNoInstanceFound
        WScript.Quit(1)
    End If
    
    For Each objInstance In trustedServiceSet
        If Ucase(objInstance.Type) = Ucase(MSServerType) and Ucase(objInstance.FQDN) = Ucase(strFqdn) Then
            If (CStr(objInstance.Version) = "3" Or CStr(objInstance.Version) = "4") Then
                'WScript.Echo "MS version:" & objInstance.Version
                CheckMSVersion = True
                Exit Function
            End If
        End IF
    Next   
     
    CheckMSVersion = False
    
End Function

Function GetTrustedQoSServerDN(strFqdn)
    ON Error resume next
    
    'List trusted service instances
    set trustedServiceSet = WMIClass.InstancesOf(TustedServiceClass)
    If IsNull(trustedServiceSet) or trustedServiceSet.Count <= 0 Then
        WScript.Echo strNoInstanceFound
        WScript.Quit(1)
    End If
    
    For Each objInstance In trustedServiceSet
        If UCase(objInstance.FQDN) = UCase(strFqdn) And UCase(objInstance.Type) = UCase(QoSServerType) Then
            If CStr(objInstance.Version) = QoSVersion Then
                QoSServerDN = objInstance.TrustedServiceDN
                'WScript.Echo QoSServerDN
                Exit Function
            Else
                WScript.Echo "Pool " & strFqdn & strPoolNotExists
                WScript.Quit(1)
            End If
        End IF
    Next
    WScript.Echo "Pool " & strFqdn & strPoolNotExists
    WScript.Quit(1)
End Function

Function UpdateAssociation(InstanceFQDN)
    ON Error resume next
    
    If IsEmptyString(InstanceFQDN) Then
        'WScript.Echo "Error. Instance FQDN is empty."
        Exit Function
    End If

    Set instanceSet = WMIClass.InstancesOf(MediationServerSetting)
    If IsNull(instanceSet) or instanceSet.Count <= 0 Then
        WScript.Echo strNoMediationServerFound
        WScript.Quit(1)
    End If
    
    'Find proper instance and update it
    bUpdated = False

    If InstanceFQDN = "*" And fDisableWideMatch Then
        WScript.Echo "Widecard characters(? or *) is not allowed for FQDN"
        WScript.Quit(1)
    Else
        For Each objInstance In instanceSet
            
            If InstanceFQDN = "*" Then
                If CheckMSVersion(objInstance.FQDN) Then
                    objInstance.TrustedQoSServer = QoSServerDN
                    objInstance.put_(wbemChangeFlagUpdateOnly)
                    CheckError("The attempt to associate Mediation Server " & objInstance.FQDN & " to Pool " & PoolFQDN &" failed.")
                    WScript.Echo "The Mediation Server " & objInstance.FQDN & " has been associated with Pool " & PoolFQDN & " successfully."
                    bUpdated = True
                End If
            Else
                bMatched = False
                If UCase(objInstance.FQDN) = UCase(InstanceFQDN) And CheckMSVersion(InstanceFQDN) Then
                        bMatched = True
                End If
                If bMatched Then
                    objInstance.TrustedQoSServer = QoSServerDN
	                objInstance.put_(wbemChangeFlagUpdateOnly)
	                CheckError("The attempt to associate Mediation Server " & InstanceFQDN & " to Pool " & PoolFQDN &" failed.")
                    bUpdated = True
                    Exit For
                End If
            End IF
        Next
    End If
    
    If bUpdated = False Then
        WScript.Echo "The Mediation Server " & InstanceFQDN & strMediationServerNotExists
    Else 
        If InstanceFQDN <> "*" Then
            WScript.Echo "The Mediation Server " & InstanceFQDN & " has been associated with Pool " & PoolFQDN & " successfully."
        End If
    End If

    WScript.Quit(0)
End Function

Function GetParameter()
    ON Error resume next
    Set arguments = WScript.Arguments
    
    If arguments.Length < 1 Then
        Exit Function
    End If
    
    bForceWildCard = False
    i = 0
    For i = 0 to arguments.Length - 1		
        Select Case Ucase(arguments(i))
            Case "-LP"
                    fListPool = True
            Case "-LM"
                    fListMediationServer = True
            Case "-P"
                    If  (i<>arguments.Length - 1) Then
                        If (left(arguments(i + 1), 1)<>"-") Then
                            i = i + 1
                            PoolFQDN = arguments(i)
                        End If
                    End If
                    
                    If IsEmptyString(PoolFQDN) Then
                        Wscript.Echo strMissingParametersForAssociate & arguments(i)
                        WScript.Quit(0)
                    End If
                    
                    fUpdateAssociation = True
            Case "-M"
                    If  (i<>arguments.Length - 1) Then
                        If (left(arguments(i + 1), 1)<>"-") Then
                            i = i + 1
                            MediationServerFQDN = arguments(i)
                        End If
                    End If
                    
                    If IsEmptyString(MediationServerFQDN) Then
                        Wscript.Echo strMissingParametersForAssociate & arguments(i)
                        WScript.Quit(0)
                    End If
                    
                    fUpdateAssociation = True
            Case "-W"
                    bForceWildCard = True
            Case Else
                    Wscript.Echo strInvalidOptions & arguments(i)
        End Select
    Next

    If MediationServerFQDN = "*" And bForceWildCard = False Then
        Wscript.Echo "Warning: All OCS 2007 or OCS 2007 R2 Mediation Servers will be associated to the same Pool if you specify * for option -M. Please add option -W if you really want to do this."
        WScript.Quit(1)
    End If
    
End Function

Function ShowUsage()
    Wscript.Echo "Associate OCS 2007 or OCS 2007 R2 Mediation Server with OCS 2007 R2 Pool"
    Wscript.Echo ""
    Wscript.Echo "Usage: cscript Associate.vbs [-P PoolFQDN] [-M MediationServerFQDN] [-LP] [-LM] [-W]"
    Wscript.Echo "Where:"
    Wscript.Echo "  -P: poolFQDN: Specify OCS 2007 R2 Pool which the Mediation Server will be associated with"
    Wscript.Echo "  -M: mediationServerFQDN: Specify Mediation Server instance which will be associated to the Pool"
    Wscript.Echo "      if * is specified as the Mediation Server FQDN and option -W is specified, all OCS 2007 or OCS 2007 R2 Mediation Servers will be associated to the Pool" 
    Wscript.Echo "  -W: Allow wildcarding on Mediation Server"   
    Wscript.Echo "  -LP: List all OCS 2007 R2 Pools"
    Wscript.Echo "  -LM: List all OCS 2007 or OCS 2007 R2 Mediation Servers" 
    Wscript.Echo "Note: "
    Wscript.Echo "  - All parameters are case insensitive."
    Wscript.Echo "  - It must be run on a machine that has the OCS 2007 or OCS 2007 R2 Admin Tools deployed"
    Wscript.Echo "Example:"
    Wscript.Echo "  - List all OCS 2007 R2 Pools"
    Wscript.Echo "       cscript Associate.vbs -LP"
    Wscript.Echo "  - List all OCS 2007 or OCS 2007 R2 Mediation Servers"
    Wscript.Echo "       cscript Associate.vbs -LM"
    Wscript.Echo "  - Associate Mediation Server whose FQDN is medsrv.myorg.com with Pool whose FQDN is pool.myorg.com"
    Wscript.Echo "       cscript Associate.vbs -P pool.myorg.com -M medsrv.myorg.com"
    WScript.Quit(0)
End Function

Function Main()
    'Connect to target machine
    Set WMIClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & WMIComputer & "\" & WMINameSpace)
    
    'Parse command line parameters
    GetParameter()

    If fUpdateAssociation Then
    
        If IsEmptyString(PoolFQDN) Or IsEmptyString(MediationServerFQDN) Then
            Wscript.Echo strPoolOrMSMissed
            Call ShowUsage()
            WScript.Quit(1)
        Else 
            'Get QoS Server DN from class MSFT_SIPTrustedServiceSetting
            Call GetTrustedQoSServerDN(PoolFQDN)

            Call UpdateAssociation(MediationServerFQDN)
        End If
    End If
    
    if fListPool Then
        ListInstances(PoolSettingClass)
    End If

    if fListMediationServer Then
        ListInstances(MediationServerSetting)
    End If

    If not (fListPool or fListMediationServer or fUpdateAssociation) Then
        Call ShowUsage()
    End If
    
    WScript.Quit(0)
End Function