# Split the list with ',' and trim the spaces from beginning and end.
# E.g. 'test1, test2, test3, test4 ' = {test1,test2,test3,test4}
$ExcludedInstances = 'clients'.Split(',') | % {$_.TrimStart().TrimEnd()}
foreach ($instance in strip-null($connections))
{
# Skip below instances:
# 1. Make sure the instance name is not empty and exclude '_total'
# 2. We have seen cases where there is an empty string and causing discovery to fail.
# 3. Exclude the performance counter instances in the exclusion list.
if (![string]::IsNullOrEmpty($instance) -and ($instance -ne '_total') -and ($ExcludedInstances -notcontains $instance))
{
TRACE('Found Connection {0}' -f $instance)
$connection = $DiscoveryData.CreateClassInstance('$MPElement[Name='Microsoft.LS.2013.Dependency.Registrar.PeerConnection']$')
$connection.AddProperty('$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$', $TargetComputer)
$connection.AddProperty('$MPElement[Name='Microsoft.LS.2013.Dependency']/Id$', $instance)
$connection.AddProperty('$MPElement[Name='System!System.Entity']/DisplayName$', ('{0} [{1}]' -f $displayName , $instance))
$DiscoveryData.AddInstance($connection)