Functions/Public/EPCTestGroup.ps1

Function Get-EPCTestGroup {
    <#
        .SYNOPSIS
        Returns a list of EPC test groups and their associated IDs
         
        .DESCRIPTION
        Returns a list of EPC test groups and their associated IDs
 
        .PARAMETER SearchString
        Filter the results to only show test groups that match the given search string
         
        .EXAMPLE
        Get-EPCTestGroup -SearchString Contoso
        Returns test groups that contain the name Contoso
 
        .NOTES
        Version 1.0
    #>


    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$SearchString,
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to pull test group list'
            $EPCListGroupsParams = New-Object -TypeName EPC.TestGrpMgmt.ListGroupsParametersType
            $EPCListGroupsParams.credentials = $EPCCred
            $EPCListGroupsParams.matchsubstring = $SearchString
            $EPCListGroupsResults = $Global:EPCWSDL_TestGrpMgmt.ListGroups($EPCListGroupsParams)
            Write-Verbose $EPCListGroupsResults.ListGroupsResponse
            
            If ($EPCListGroupsResults.ListGroupsResponse -eq 'success') {
                Return $EPCListGroupsResults.ListGroupsGroupList
            }
            Else {
                Throw $EPCListGroupsResults.ListGroupsResponse
            }
        }
        Else {
            Write-Verbose 'Using XML to pull test group list'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                 <soapenv:Header/>
                 <soapenv:Body>
                 <urn:ListGroupsMatchingString>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                <matchsubstring>$SearchString</matchsubstring>
                 </urn:ListGroupsMatchingString>
                 </soapenv:Body>
                </soapenv:Envelope>"

                
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/ListGroupsMatchingString'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCListGroupsResults = $XMLResponse.Envelope.Body.ListGroupsResults
            
            If ($EPCListGroupsResults.ListGroupsResponse -eq 'success') {
                If ($EPCListGroupsResults.ListGroupsGroupList) {
                    [psobject]$ListGroups = $EPCListGroupsResults.ListGroupsGroupList | ConvertFrom-XMLElement
                    Return $ListGroups
                }
                Else {
                    Write-Error "Could not find a group called $SearchString"
                }
            }
            Else {
                Throw $EPCListGroupsResults.ListGroupsResponse
            }
        }
    }
}


Function Set-EPCTestGroup {
    <#
        .SYNOPSIS
        Update the name of an existing test group
         
        .DESCRIPTION
        Update the name of an existing test group
         
        .PARAMETER Name
        The name of the test group to update
 
        .PARAMETER NewName
        The new name of the test group
         
        .PARAMETER TGID
        The ID of a test group. If both Name and TGID are specified, Name will take priority.
         
        .EXAMPLE
        Set-EPCTestGroup -Name 'Existing Name' -NewName 'New Name'
 
        .NOTES
        Version 1.0
    #>


    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$GroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$GroupID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$NewGroupName,
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($GroupName -And !$GroupID) { 
            $GroupIDList = (Get-EPCTestGroup -SearchString $GroupName).GroupID
            If ($GroupIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified group name. Please refine your search to return a single group or use GroupID parameter.' 
            }
            Else {
                $GroupID = $GroupIDList
            }
        }
        
        If (!$GroupID) { Throw 'Test Group ID not specified or could not be found' }
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to set test group parameters'
            $EPCModifyGroupParams = New-Object -TypeName EPC.TestGrpMgmt.ModifyGroupParametersType
            $EPCModifyGroupParams.credentials = $EPCCred
            $EPCModifyGroupParams.ModifyGroupID = $GroupID
            $EPCModifyGroupParams.ModifyGroupUpdatedName = $NewGroupName
            $EPCModifyGroupResults = $Global:EPCWSDL_TestGrpMgmt.ModifyGroup($EPCModifyGroupParams)
            Write-Verbose $EPCModifyGroupResults.ModifyGroupResponse
        }
        Else {
            Write-Verbose 'Using XML to set test group parameters'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                 <urn:ModifyGroupParameters>
                  <credentials>
                   <username>$($Global:EPControllerCred.UserName)</username>
                   <password>$PwdEscaped</password>
                  </credentials>
                  <ModifyGroupID>$GroupID</ModifyGroupID>
                  <ModifyGroupUpdatedName>$NewGroupName</ModifyGroupUpdatedName>
                 </urn:ModifyGroupParameters>
                </soapenv:Body>
                </soapenv:Envelope>"

                
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/ModifyGroupParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCModifyGroupResults = $XMLResponse.Envelope.Body.ModifyGroupResults
        }
        
        If ($EPCModifyGroupResults.ModifyGroupResponse -eq 'success') {
            Return $EPCModifyGroupResults.ModifyGroupResponse
        }
        Else {
            Throw $EPCModifyGroupResults.ModifyGroupResponse
        }
    }
}


Function New-EPCTestGroup {
    <#
        .SYNOPSIS
        Create a new EPC test group
         
        .DESCRIPTION
        Create a new EPC test group
         
        .PARAMETER GroupName
        The name of the test group
         
        .PARAMETER GroupType
        The type to assign to the test group
         
        .EXAMPLE
        New-EPCTestGroup -GroupName MyGroup -GroupType Agent
        Creates an agent test group called MyGroup
 
        .NOTES
        Version 1.0
    #>


    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$GroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [ValidateSet('Agent','Network Entity','DHCP','DNS','HTTP','POP3','SIP Endpoint','SMTP', IgnoreCase=$True)]
        [string]$GroupType = 'Agent',
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to create test group'
            $EPCAddGroupParams = New-Object -TypeName EPC.TestGrpMgmt.AddGroupParametersType
            $EPCAddGroupParams.credentials = $EPCCred
            $EPCAddGroupParams.AddGroupGroupName = $GroupName
            $EPCAddGroupParams.GroupType = $GroupType
            $EPCAddGroupResults = $Global:EPCWSDL_TestGrpMgmt.AddGroup($EPCAddGroupParams)
            Write-Verbose $EPCAddGroupResults.AddGroupResponse
        }
        Else {
            Write-Verbose 'Using XML to create test group'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                 <urn:AddGroupParameters>
                  <credentials>
                   <username>$($Global:EPControllerCred.UserName)</username>
                   <password>$PwdEscaped</password>
                  </credentials>
                  <AddGroupGroupName>$GroupName</AddGroupGroupName>
                  <GroupType>$($GroupType.ToLower())</GroupType>
                 </urn:AddGroupParameters>
                </soapenv:Body>
                </soapenv:Envelope>"

                
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/AddGroupParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCAddGroupResults = $XMLResponse.Envelope.Body.AddGroupResults
        }
        
        If ($EPCAddGroupResults.AddGroupResponse -eq 'success') {
            Return $EPCAddGroupResults
        }
        Else {
            Throw $EPCAddGroupResults.AddGroupResponse
        }
    }
}


Function Remove-EPCTestGroup {
    <#
        .SYNOPSIS
        Remove an EPC test group
         
        .DESCRIPTION
        Remove an EPC test group
         
        .PARAMETER GroupName
        The name of the test group to remove. Use either this or GroupID.
         
        .PARAMETER GroupID
        The ID of the test group to remove. Use either this or GroupName.
         
        .EXAMPLE
        Remove-EPCTestGroup -GroupName MyGroup
        Removes the test group called MyGroup
 
        .NOTES
        Version 1.0
    #>


    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$GroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$GroupID,
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($GroupName -And !$GroupID) { 
            $GroupIDList = (Get-EPCTestGroup -SearchString $GroupName).GroupID
            If ($GroupIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified group name. Please refine your search to return a single group or use GroupID parameter.' 
            }
            Else {
                $GroupID = $GroupIDList
            }
        }
        
        If (!$GroupID) { Throw 'Test Group ID not specified or could not be found' }
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to delete test group'
            $EPCDeleteGroupParams = New-Object -TypeName EPC.TestGrpMgmt.DeleteGroupParametersType
            $EPCDeleteGroupParams.credentials = $EPCCred
            $EPCDeleteGroupParams.DeleteGroupID = $GroupID
            $EPCDeleteGroupResults = $Global:EPCWSDL_TestGrpMgmt.DeleteGroup($EPCDeleteGroupParams)
            Write-Verbose $EPCDeleteGroupResults.DeleteGroupResponse
        }
        Else {
            Write-Verbose "Using XML to delete test group with ID $GroupID"
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                 <urn:DeleteGroupWithID>
                  <credentials>
                   <username>$($Global:EPControllerCred.UserName)</username>
                   <password>$PwdEscaped</password>
                  </credentials>
                  <DeleteGroupID>$GroupID</DeleteGroupID>
                 </urn:DeleteGroupWithID>
                </soapenv:Body>
                </soapenv:Envelope>"

                
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/DeleteGroupWithID'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCDeleteGroupResults = $XMLResponse.Envelope.Body.DeleteGroupResults
        }
        
        If ($EPCDeleteGroupResults.DeleteGroupResponse -eq 'success') {
            Return $EPCDeleteGroupResults
        } Else {
            Throw $EPCDeleteGroupResults.DeleteGroupResponse
        }
    }
}


Function Get-EPCTestGroupMembers {
    <#
        .SYNOPSIS
        Returns a list of test points associated with a given test group
         
        .DESCRIPTION
        Returns a list of test points associated with a given test group
         
        .EXAMPLE
        Get-EPCTestGroupMembers -GroupID 4
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(Mandatory=$False)]
        [string]$GroupName,        
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$GroupID,
        [switch]$UseXML    
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($GroupName -And !$GroupID) { 
            $GroupIDList = (Get-EPCTestGroup -SearchString $GroupName).GroupID
            If ($GroupIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified GroupName. Please refine your search to return a single group or use GroupID parameter.' 
            }
            Else {
                $GroupID = $GroupIDList
            }
        }
        
        If (!$GroupID) { Throw 'Test Group ID not specified or could not be found' }

        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to pull test group member list'
            $EPCListEndpointsInGroupParams = New-Object -TypeName EPC.TestGrpMgmt.ListEndpointsInGroupParametersType
            $EPCListEndpointsInGroupParams.credentials = $EPCCred
            $EPCListEndpointsInGroupParams.GroupID = $GroupID    
            $EPCListEndpointsInGroupResults = $Global:EPCWSDL_TestGrpMgmt.ListEndpointsInGroup($EPCListEndpointsInGroupParams)
            Write-Verbose $EPCListEndpointsInGroupResults.ListEndpointsGroupResponse
            
            If ($EPCListEndpointsInGroupResults.ListEndpointsGroupResponse -eq 'success') {
                Return $EPCListEndpointsInGroupResults.EndpointIDList
            }
            Else {
                Throw $EPCListEndpointsInGroupResults.ListEndpointsGroupResponse
            }
        }
        Else {
            Write-Verbose "Using XML to pull test group member list from group with id $GroupID"
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                 <urn:ListEndpointsInGroupWithID>
                  <credentials>
                   <username>$($Global:EPControllerCred.UserName)</username>
                   <password>$PwdEscaped</password>
                  </credentials>
                  <GroupID>$GroupID</GroupID>
                 </urn:ListEndpointsInGroupWithID>
                </soapenv:Body>
                </soapenv:Envelope>"

                
            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/ListEndpointsInGroupWithID'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $ListGroupMembersResults = $XMLResponse.Envelope.Body.ListEndpointsInGroupResults
            
            If ($ListGroupMembersResults.ListEndpointsGroupResponse -eq 'success') {
                If ($ListGroupMembersResults.EndpointIDList) { # Only return results if the list exists
                    [psobject]$ListGroupMembers = $ListGroupMembersResults.EndPointIDList | ConvertFrom-XMLElement
                    Return $ListGroupMembers
                }
            }
            Else {
                Throw $ListGroupMembersResults.ListEndpointsGroupResponse
            }
        }
    }
}    


Function Add-EPCTestGroupMember {
    <#
        .SYNOPSIS
        Adds an EPC test point to an EPC test group
         
        .DESCRIPTION
        Adds an EPC test point to an EPC test group
         
        .PARAMETER TestGroupName
        The name of the test group to add the member to. Use either this or TestGroupID
         
        .PARAMETER TestGroupID
        The ID of the test group to add the member to. Use either this or TestGroupName
         
        .PARAMETER ResourceGroupName
        The name of the resource group associated with this test group
         
        .PARAMETER TestPointName
        The name of the test point to add to the test group
         
        .PARAMETER InterfaceID
        The interface ID of the test point
         
        .PARAMETER IPAddress
        The IP address associated with the given interface
         
        .EXAMPLE
        Add-EPCTestGroupMember -TestGroupName MyTestGroup -ResourceGroupName MyRG -TestPointName 'TFerguson laptop' -InterfaceID 'Primary Network Adapter' -IPAddress '192.168.1.20'
        Adds the given test point to the MyTestGroup test group
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$TestGroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$TestGroupID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$ResourceGroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$ResourceGroupID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [Alias('name')]
        [string]$TestPointName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [Alias('TestPtID')]
        [string]$TestPointID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$InterfaceID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$IPAddress,
        [switch]$UseXML
    )
    
    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($TestGroupName -And !$TestGroupID) { 
            $TestGroupIDList = (Get-EPCTestGroup -SearchString $TestGroupName).GroupID
            If ($TestGroupIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified test group name. Please refine your search to return a single test group or use TestGroupID parameter.' 
            }
            Else {
                [int]$TestGroupID = $TestGroupIDList
            }
        }
        
        If (!$TestGroupID) { Throw 'Test Group ID not specified or could not be found' }

        If ($TestPointName -And !$TestPointID) { 
            $TestPointIDList = (Get-EPCTestPoint -Name $TestPointName).TestPtID
            If ($TestPointIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified TestPoint name. Please refine your search to return a single testpoint or use TestPointID parameter.' 
            }
            Else {
                $TestPointID = $TestPointIDList
            }
        }
        
        If (!$TestPointID) { Throw 'TestPoint ID not specified or could not be found' }

        
        If ($ResourceGroupName -And !$ResourcegroupID) { $ResourceGroupID = (Get-EPCResourceGroup | Where-Object {$_.RGName -eq $ResourceGroupName}).RGID }
        If (!$ResourceGroupID) { Throw 'Resource Group ID not specified or could not be found' }

        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to add test point to group'
            # Put the endpoint details into an object
            $AgentDetails = New-Object -TypeName EPC.TestGrpMgmt.AgentType

            $AgentDetails.TestPointID = $TestPointID
            $AgentDetails.InterfaceID = $InterfaceID
            $AgentDetails.IPAddress = $IPAddress
            $AgentDetails.ResourceGroupID = $ResourceGroupID
            
            $EPCAddEndpointToGroupParams = New-Object -TypeName EPC.TestGrpMgmt.AddEndpointToGroupParametersType
            $EPCAddEndpointToGroupParams.credentials = $EPCCred
            $EPCAddEndpointToGroupParams.ToGroupID = $TestGroupID
            $EPCAddEndpointToGroupParams.Item = $AgentDetails
            $EPCAddEndpointToGroupResults = $Global:EPCWSDL_TestGrpMgmt.AddEndpointToGroup($EPCAddEndpointToGroupParams)
            Write-Verbose $EPCAddEndpointToGroupResults.AddEndpointToGroupResponse
        }
        Else {
            Write-Verbose 'Using XML to add test point to group'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)

            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                <urn:AddEndpointToGroupParameters>
                <credentials>
                <username>$($Global:EPControllerCred.UserName)</username>
                <password>$PwdEscaped</password>
                </credentials>
                <ToGroupID>$TestGroupID</ToGroupID>
                <Agent>
                <TestPointID>$TestPointID</TestPointID>
                <ResourceGroupID>$ResourceGroupID</ResourceGroupID>
                <InterfaceID>$InterfaceID</InterfaceID>
                <IPAddress>$IPAddress</IPAddress>
                </Agent>
                </urn:AddEndpointToGroupParameters>
                </soapenv:Body>
                </soapenv:Envelope>"


            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/AddEndpointToGroupParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCAddEndpointToGroupResults = $XMLResponse.Envelope.Body.AddEndpointToGroupResults
        }
        
        If ($EPCAddEndpointToGroupResults.AddEndpointToGroupResponse -eq 'success') {
            Return $EPCAddEndpointToGroupResults.AddEndpointToGroupResponse
        }
        Else {
            Throw $EPCAddEndpointToGroupResults.AddEndpointToGroupResponse
        }
    }
}    


Function Remove-EPCTestGroupMember {
    <#
        .SYNOPSIS
        Removes an EPC test point from an EPC test group
         
        .DESCRIPTION
        Removes an EPC test point from an EPC test group
         
        .PARAMETER GroupName
        The name of the test group to remove the member from
         
        .PARAMETER GroupID
        The ID of the test group to remove the member from
         
        .PARAMETER TestPointName
        The name of the test point to remove from the test group
         
        .PARAMETER TestPointID
        The ID of the test point to remove from the test group
         
        .EXAMPLE
        Remove-EPCTestGroupMember -GroupName MyGroup -TestPointName TPTest
        Removes TPTest from the MyGroup group
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [string]$GroupName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [int]$GroupID,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [Alias('Name','EndpointName')]
        [string]$TestPointName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$False)]
        [Alias('TestPtID','EndpointID')]
        [string]$TestPointID,
        [switch]$UseXML
    )

    Begin {
        Connect-EPCController
        
        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            $EPCCred = New-Object -TypeName EPC.TestGrpMgmt.CredentialsType
            $EPCCred.username = $Global:EPControllerCred.UserName
            $EPCCred.password = $Global:EPControllerCred.GetNetworkCredential().Password
        }
        Else {
            $ProgressPreference = 'SilentlyContinue'
        }
    }
    Process {
        If ($GroupName -And !$GroupID) { 
            $GroupIDList = (Get-EPCTestGroup -SearchString $GroupName).GroupID
            If ($GroupIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified test group name. Please refine your search to return a single test group or use TestGroupID parameter.' 
            }
            Else {
                $GroupID = $GroupIDList
            }
        }
        
        If (!$GroupID) { Throw 'Test Group ID not specified or could not be found' }
        

        If ($TestPointName -And !$TestPointID) { 
            $TestPointIDList = (Get-EPCTestPoint -Name $TestPointName).TestPtID
            If ($TestPointIDList.Count -gt 1) { 
                Throw 'Too many results returned for specified TestPoint name. Please refine your search to return a single testpoint or use TestPointID parameter.' 
            }
            Else {
                $TestPointID = $TestPointIDList
            }
        }
        
        If (!$TestPointID) { Throw 'TestPoint ID not specified or could not be found' }

        If ($Global:EPC_UseWSDL -And $UseXML -eq $False) {
            Write-Verbose 'Using WSDL to remove test point from group'
            $EPCDeleteEndpointFromGroupParams = New-Object -TypeName EPC.TestGrpMgmt.DeleteEndpointFromGroupParametersType
            $EPCDeleteEndpointFromGroupParams.credentials = $EPCCred
            $EPCDeleteEndpointFromGroupParams.FromGroupID = $GroupID
            $EPCDeleteEndpointFromGroupParams.DeleteEndpointID = $TestPointID
            $EPCDeleteEndpointFromGroupResults = $Global:EPCWSDL_TestGrpMgmt.DeleteEndpointFromGroup($EPCDeleteEndpointFromGroupParams)
            Write-Verbose $EPCDeleteEndpointFromGroupResults.DeleteEndpointFromGroupResponse

        }
        Else {
            Write-Verbose 'Using XML to remove test point from group'
            $PwdEscaped = [System.Security.SecurityElement]::Escape($Global:EPControllerCred.GetNetworkCredential().Password)
            [xml]$SOAPReq = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
                xmlns:urn='urn:telchemyTestGroupManagement'>
                <soapenv:Header/>
                <soapenv:Body>
                <urn:DeleteEndpointFromGroupParameters>
                 <credentials>
                  <username>$($Global:EPControllerCred.UserName)</username>
                  <password>$PwdEscaped</password>
                 </credentials>
                 <DeleteEndpointID>$TestPointID</DeleteEndpointID>
                 <FromGroupID>$GroupID</FromGroupID>
                 </urn:DeleteEndpointFromGroupParameters>
                 </soapenv:Body>
                </soapenv:Envelope>"


            $SOAPFQDN = "https://$Global:EPControllerFQDN/telchemywebservices/services/telchemyTestGroupManagementService"
            Write-Verbose $SOAPFQDN
            Write-Verbose $SOAPReq.OuterXML

            If ($Global:EPC_UseSOAPHeader) {
                $Headers = @{'SOAPAction' = 'urn:telchemyTestGroupManagement/DeleteEndpointFromGroupParameters'}
            } Else {
                $Headers = @{}
            }
            
            [xml]$XMLResponse = (Invoke-WebRequest -UseBasicParsing -Method POST -URI $SOAPFQDN -Headers $Headers -Body $SOAPReq -ContentType 'text/xml').Content
            $EPCDeleteEndpointFromGroupResults = $XMLResponse.Envelope.Body.DeleteEndpointFromGroupResults
        }
        
        If ($EPCDeleteEndpointFromGroupResults.DeleteEndpointFromGroupResponse -eq 'success') {
            Return $EPCDeleteEndpointFromGroupResults.DeleteEndpointFromGroupResponse
        }
        Else {
            Throw $EPCDeleteEndpointFromGroupResults.DeleteEndpointFromGroupResponse
        }
    }
}    


Function Find-EPCTestGroupMember {
    <#
        .SYNOPSIS
        Returns the EPC test group that a test point is a member of
         
        .DESCRIPTION
        Returns the EPC test group that a test point is a member of
         
        .PARAMETER GroupNamePrefix
        The starting text of the group names used for the customer
         
        .PARAMETER TestPointName
        The name of the test point to remove from the test group
         
        .EXAMPLE
        Find-EPCTestGroupMember -GroupNamePrefix Contoso -TestPointName TPTest
        Returns the group name the TPTest testpoint is a member of
 
        .NOTES
        Version 1.0
    #>

    
    [cmdletbinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [string]$GroupNamePrefix,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory=$True)]
        [Alias('Name','EndpointName')]
        [string]$TestPointName
    )

    Begin {
        $TestGroupList = Get-EPCTestGroup -SearchString $GroupNamePrefix
        $TGResults = @()
    }
    
    Process {
        ForEach ($TG in $TestGroupList) {
            $TGMembers = Get-EPCTestGroupMembers -GroupID $TG.GroupID
            If ($TestPointName -in $TGMembers.EndpointName) {
                $TGResults += [pscustomobject][ordered]@{ 'TestPointName' = $TestPointName; 'GroupName' = $TG.GroupName }
                Break
            }
        }
    }
    End {
        Return $TGResults
    }
}