<commit_before>function Get-TargetMachines {
    [CmdletBinding()]
    Param (
        [string[]] $targetMachineNames,
        [pscredential] $credential,
        [string] $authentication,
        [string] $sessionConfigurationName,
        [switch] $useSsl
    )
    Trace-VstsEnteringInvocation -InvocationInfo $MyInvocation -Parameter ''
    try {
        Write-Verbose "Target Machines: $($targetMachineNames -join ',')"
        $targetMachines = @();
        foreach($targetMachineName in $targetMachineNames) {
            $targetMachine = @{
                ComputerName = "";
                WSManPort = "";
                Credential = $credential;
                Authentication = $authentication;
                SessionConfigurationName = $sessionConfigurationName;
                UseSsl = $useSsl
            }
        
            # if port if provided with machine name, use it, else default it based on protocol
            $computerName, $port = $targetMachineName.Split(':');
            if([string]::IsNullOrEmpty($port)) {
                if($useSsl) {
                    $port = "5986"
                } else {
                    $port = "5985"
                }
            }
            $targetMachine.ComputerName = $computerName.Trim()
            $targetMachine.WSManPort = $port.Trim()

            Write-Verbose "ComputerName = $($targetMachine.ComputerName)"
            Write-Verbose "WSManPort = $($targetMachine.WSManPort)"
            Write-Verbose "Authentication = $($targetMachine.Authentication)"
            Write-Verbose "SessionConfigurationName = $($targetMachine.SessionConfigurationName)"
            Write-Verbose "UseSSL = $($targetMachine.UseSsl)"
            $targetMachines += $targetMachine
        }
        Write-Verbose "Total target machines are: $($targetMachines.Length)"
        return $targetMachines
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}

function Publish-Telemetry {
    Param([hashtable[]] $jobResults)
    Trace-VstsEnteringInvocation -InvocationInfo $MyInvocation -Parameter ''
    try {
        $buildOrReleaseJobId = Get-VstsTaskVariable -Name 'System.JobId'
        foreach($jobResult in $jobResults) {
            $telemetryData = @{
                "IsAzureVm" = $jobResult.IsAzureVM;
                "VmUuidHash" = $jobResult.MachineGuidHash;
                # field name 'TelemetryError' is misleading here. TelemetryError is only the type of the Telemetry exception.
                "TelemetryError" = $jobResult.TelemetryError;
                "JobId" = $buildOrReleaseJobId;
            }
            $telemetryDataJson = ConvertTo-Json $telemetryData
            $telemetryDataJson = $telemetryDataJson.Replace([environment]::NewLine, '').Trim()
            Write-Verbose "Telemetry Data is: $telemetryDataJson"
            $telemetry = "##vso[telemetry.publish area=TaskHub;feature=PowerShellOnTargetMachines]$telemetryDataJson"
            Write-Host $telemetry
        }
    } catch {
        Write-Verbose "Unable to publish telemetry data. Error: $($_.Exception.Message)"
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}

function Get-TemporaryLogsFolder {
    Trace-VstsEnteringInvocation $MyInvocation
    try {
        $agentTempDirectory = Get-VstsTaskVariable -Name 'Agent.TempDirectory'
        $tempFolderName = [Guid]::NewGuid().ToString()
        $tempLogsFolder = [System.IO.Path]::Combine($agentTempDirectory, $tempFolderName)
        if((Test-Path -LiteralPath $tempLogsFolder -PathType 'Container') -eq $true) {
            Remove-Item -LiteralPath $tempLogsFolder -Force
        }
        $tempLogsFolder = (New-Item -Path $agentTempDirectory -Name $tempFolderName -ItemType 'Container').FullName
        return $tempLogsFolder
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}
<commit_msg>recursively delete logs folder and add trace (#7232)<commit_after>function Get-TargetMachines {
    [CmdletBinding()]
    Param (
        [string[]] $targetMachineNames,
        [pscredential] $credential,
        [string] $authentication,
        [string] $sessionConfigurationName,
        [switch] $useSsl
    )
    Trace-VstsEnteringInvocation -InvocationInfo $MyInvocation -Parameter ''
    try {
        Write-Verbose "Target Machines: $($targetMachineNames -join ',')"
        $targetMachines = @();
        foreach($targetMachineName in $targetMachineNames) {
            $targetMachine = @{
                ComputerName = "";
                WSManPort = "";
                Credential = $credential;
                Authentication = $authentication;
                SessionConfigurationName = $sessionConfigurationName;
                UseSsl = $useSsl
            }
        
            # if port if provided with machine name, use it, else default it based on protocol
            $computerName, $port = $targetMachineName.Split(':');
            if([string]::IsNullOrEmpty($port)) {
                if($useSsl) {
                    $port = "5986"
                } else {
                    $port = "5985"
                }
            }
            $targetMachine.ComputerName = $computerName.Trim()
            $targetMachine.WSManPort = $port.Trim()

            Write-Verbose "ComputerName = $($targetMachine.ComputerName)"
            Write-Verbose "WSManPort = $($targetMachine.WSManPort)"
            Write-Verbose "Authentication = $($targetMachine.Authentication)"
            Write-Verbose "SessionConfigurationName = $($targetMachine.SessionConfigurationName)"
            Write-Verbose "UseSSL = $($targetMachine.UseSsl)"
            $targetMachines += $targetMachine
        }
        Write-Verbose "Total target machines are: $($targetMachines.Length)"
        return $targetMachines
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}

function Publish-Telemetry {
    Param([hashtable[]] $jobResults)
    Trace-VstsEnteringInvocation -InvocationInfo $MyInvocation -Parameter ''
    try {
        $buildOrReleaseJobId = Get-VstsTaskVariable -Name 'System.JobId'
        foreach($jobResult in $jobResults) {
            $telemetryData = @{
                "IsAzureVm" = $jobResult.IsAzureVM;
                "VmUuidHash" = $jobResult.MachineGuidHash;
                # field name 'TelemetryError' is misleading here. TelemetryError is only the type of the Telemetry exception.
                "TelemetryError" = $jobResult.TelemetryError;
                "JobId" = $buildOrReleaseJobId;
            }
            $telemetryDataJson = ConvertTo-Json $telemetryData
            $telemetryDataJson = $telemetryDataJson.Replace([environment]::NewLine, '').Trim()
            Write-Verbose "Telemetry Data is: $telemetryDataJson"
            $telemetry = "##vso[telemetry.publish area=TaskHub;feature=PowerShellOnTargetMachines]$telemetryDataJson"
            Write-Host $telemetry
        }
    } catch {
        Write-Verbose "Unable to publish telemetry data. Error: $($_.Exception.Message)"
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}

function Get-TemporaryLogsFolder {
    Trace-VstsEnteringInvocation $MyInvocation
    try {
        $agentTempDirectory = Get-VstsTaskVariable -Name 'Agent.TempDirectory'
        $tempFolderName = [Guid]::NewGuid().ToString()
        $tempLogsFolder = [System.IO.Path]::Combine($agentTempDirectory, $tempFolderName)
        if((Test-Path -LiteralPath $tempLogsFolder -PathType 'Container') -eq $true) {
            Remove-Item -LiteralPath $tempLogsFolder -Recurse -Force
        }
        $tempLogsFolder = (New-Item -Path $agentTempDirectory -Name $tempFolderName -ItemType 'Container').FullName
        Write-Verbose "Created temporary logs folder: $tempLogsFolder"
        return $tempLogsFolder
    } finally {
        Trace-VstsLeavingInvocation $MyInvocation
    }
}

{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.002544853034737244, 'mean_word_length': 2.3632862644415917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '411885', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2126, 'n_words': 418}