skype cls logging in debugger mode on SIP

Syntax to use the script:
.\CollectCLSLogs -Pools Lync2013.sunily13.com -ScenarioName "MSFT" -LogFolder D:\Logs
Param(
	[Parameter(Mandatory=$true)][string]$Pools,
    [Parameter(Mandatory=$true)][string]$ScenarioName,
    [Parameter(Mandatory=$true)][string]$LogFolder
)

$FEPoolFQDN = $Pools
$FEScenarioName = $ScenarioName

if ( !($(Get-CsClsScenario -Identity "Global/$($FEScenarioName)" -ErrorAction SilentlyContinue ) -ne $null) )
{
    Write-Host "Creating Scenario: Global/$($FEScenarioName)" 
    #Remove-CsClsScenario -Identity "Global/$($FEScenarioName)"
    Start-Sleep 5

    $FEComponents = New-Object System.Collections.ArrayList
	
	$FEComponents.Add( $(New-CsClsProvider -Name "SIPStack" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
	
	<#
	$FEComponents.Add( $(New-CsClsProvider -Name "S4" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
	$FEComponents.Add( $(New-CsClsProvider -Name "ASMCU" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
	$FEComponents.Add( $(New-CsClsProvider -Name "AVMCU" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
	$FEComponents.Add( $(New-CsClsProvider -Name "MCUInfra" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
	$FEComponents.Add( $(New-CsClsProvider -Name "MCUFactory" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "udcagent" -Type "WPP" -Level "Verbose" -Flags "All") ) | Out-Null    
    	
	$FEComponents.Add( $(New-CsClsProvider -Name "ABCommon" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "ABServer" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "ABServerIISModule" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "WebInfrastructure" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    
 
    $FEComponents.Add( $(New-CsClsProvider -Name "ADConnect" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RGSClientLib" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsCommonLibrary" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsDatastores" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsDeploymentApi" -Type "WPP" -Level "Debug" -Flags "ALL") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsDeploymentLibrary" -Type "WPP" -Level "Debug" -Flags "ALL") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsDiagnostics" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsHostingFramework" -Type "WPP" -Level "Debug" -Flags "ALL") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsMatchMakingService" -Type "WPP" -Level "Debug" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "RgsDBSyncAgent" -Type "WPP" -Level "Debug" -Flags "ALL") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "Sipstack" -Type "WPP" -Level "Verbose" -Flags "All") ) | Out-Null
    $FEComponents.Add( $(New-CsClsProvider -Name "S4" -Type "WPP" -Level "Verbose" -Flags "ALL") ) | Out-Null
    #>
    New-CsClsScenario -Identity "global/$($FEScenarioName)" -Provider @{Add=$FEComponents}
}

else {Write-Host "Scenario exists: Global/$($FEScenarioName)" }

function WaitforCMSReplication ($Pool, $TimeOut)
{
    $sw = [Diagnostics.Stopwatch]::StartNew()
    $i = 0;
    While($true)
    {
        $Replicas = $(Get-CsPool $Pool).Computers | % { Get-CsManagementStoreReplicationStatus -ReplicaFqdn $_}
        $RepStatus = "True"
        foreach ($Server in $Replicas)
        {
            if ($Server.UptoDate -match "False")
            {
                $RepStatus = "False"
                if ($i -lt 1) { Write-Host "Waiting for CMS Replication $($Pool)" -NoNewline}
                Write-Host "." -NoNewline
                $i=1;
            }
        }
    
        if($RepStatus -match "True" )
        {
           Write-Host "Done!"
           #exit $True
           #Break
           Return
        }

        if ($sw.Elapsed.Seconds -gt $Timeout)
        {
            Write-Host "`nReplication Timeout."
            #Write-Error "Replication Timeout $Timeout seconds" -Category OperationTimeout
            #exit $False
            #Break
            return 1

        }
        Start-Sleep -Seconds 3
    }
} 

Invoke-CsManagementStoreReplication
WaitforCMSReplication $FEPoolFQDN 200

Start-Sleep 10

#Start the logging

$StartTime = Get-Date

Start-CsClsLogging –Scenario "$($FEScenarioName)" –Pools $FEPoolFQDN -Duration 0.00:30    #[ for 30 minutes]

#Get-CsClsScenario  "Global/$($FEScenarioName)"


Write-Host "`nLogging is started. Reproduce the issue now."  -ForegroundColor Green
# 5. Stop the logging

$key = Read-Host "Press 'Y' to Stop Logging "
if ($key -notmatch 'Y') {Write-Host " "}
else
{
    Write-Host "`nStopping Logging" -ForegroundColor Green
    Stop-CsClsLogging –Scenario $FEScenarioName –Pools $FEPoolFQDN
} 

Sync-CsClslogging -Pools $FEPoolFQDN
Start-Sleep -Seconds 5

$StopTime = Get-Date
$TotalMin = ($($StopTime - $StartTime).TotalSeconds)/60
if ( ($TotalMin -gt 0) -and ($TotalMin -lt 1) ) {$TotalMin = 1}
[int]$TotalMin = $TotalMin

Write-Host "`nLogging Start Time : $($StartTime.ToString("hh:mm:ss-tt")) `nLogging Stop Time : $($StopTime.ToString("hh:mm:ss-tt"))" -ForegroundColor Green

Search-CsCLSLogging -Pools $FEPoolFQDN -StartTime  (Get-Date).AddMinutes(-$TotalMin).ToString("MM/dd/yyyy hh:mm:ss tt") -EndTime (Get-Date).ToString("MM/dd/yyyy hh:mm:ss tt") -OutputFilePath "$($LogFolder)\FEPoolCLS-$(($StopTime).ToString("yyyy-MM-dd-hh-mm-ss-tt")).txt"

Write-Host "`nLog files created :" -ForegroundColor Cyan
if ( Test-Path ("$($LogFolder)\FEPoolCLS-$(($StopTime).ToString("yyyy-MM-dd-hh-mm-ss-tt")).txt") )
{
    "$($LogFolder)\FEPoolCLS-$(($StopTime).ToString("yyyy-MM-dd-hh-mm-ss-tt")).txt"
}