<commit_before>function Get-DSPTrustedHosts()
{
	(get-item wsman:\localhost\Client\TrustedHosts).value
}

function Add-DSPTrustedHosts()
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory=$true, Position=1)]
		[string]$proposedHost
	)

    if (Test-DSPIsAdmin)
    {
        $trustedHosts = Get-DSPTrustedHosts

        if (!$trustedHosts.split(",").Contains($proposedHost))
        {
            Write-Host "Adding $proposedHost to Trusted Hosts : $trustedHosts ... " -nonewline -foregroundcolor yellow
            
            if ( [string]::IsNullOrEmpty($trustedHosts) )
            {
                $pattern = $proposedHost
            }
            else
            {
                $pattern = "$trustedHosts,$proposedHost"
            }
                        
            Set-Item wsman:\localhost\Client\TrustedHosts -value $pattern -Force
            Write-Host "DONE! " -nonewline -foregroundcolor green
            Write-Host "Restarting WinRM service... " -nonewline -foregroundcolor yellow
            
            Restart-Service WinRM
            Write-Host "DONE!" -foregroundcolor green
        }
    }
    else 
    {
        Write-Host "YOU ARE NOT AN ADMINISTRATOR. YOU CAN'T UPDATE THE TRUSTED HOSTS"
    }
}

function Initialize-DSPRemotePowerShell()
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory=$true, Position=1)]
		[string]$proposedHost
	)

    # Enable PowerShell Remoting
    Enable-PSRemoting -Force

    # Add Hostname to Trusted Hostname
    Add-DSPTrustedHosts $proposedHost
}

function Enter-DSPRemoteSession()
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory=$true, Position=0)]
		[string]$Username,

        [Parameter(Mandatory=$true, Position=1)]
		[string]$Password,

        [Parameter(Mandatory=$true, Position=2)]
		[string]$ComputerName 
	)

	[SecureString]$securePassword = $null
	# If password is a path, consider it an encrypted password file
	if(Test-Path $Password)
	{
		$securePassword = Get-Content $Password | ConvertTo-SecureString
	}
	else
	{
		$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
	}

    $cred = New-Object System.Management.Automation.PSCredential ($Username, $securePassword)
    Enter-PSSession ComputerName $ComputerName Credential $cred -Authentication Credssp
}<commit_msg>[DSP] Remote Powershell : Enable CredSSP delegation in client. This step seems to be needed for some remotes. Need to investigate with a broader variety of environment (Azure vs LocalVM). (fix tabs for spaces)<commit_after>function Get-DSPTrustedHosts()
{
    (get-item wsman:\localhost\Client\TrustedHosts).value
}

function Add-DSPTrustedHosts()
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true, Position=1)]
        [string]$proposedHost
    )

    if (Test-DSPIsAdmin)
    {
        $trustedHosts = Get-DSPTrustedHosts

        if (!$trustedHosts.split(",").Contains($proposedHost))
        {
            Write-Host "Adding $proposedHost to Trusted Hosts : $trustedHosts ... " -nonewline -foregroundcolor yellow
            
            if ( [string]::IsNullOrEmpty($trustedHosts) )
            {
                $pattern = $proposedHost
            }
            else
            {
                $pattern = "$trustedHosts,$proposedHost"
            }
                        
            Set-Item wsman:\localhost\Client\TrustedHosts -value $pattern -Force
            Write-Host "DONE! " -nonewline -foregroundcolor green
            Write-Host "Restarting WinRM service... " -nonewline -foregroundcolor yellow
            
            Restart-Service WinRM
            Write-Host "DONE!" -foregroundcolor green
        }
    }
    else 
    {
        Write-Host "YOU ARE NOT AN ADMINISTRATOR. YOU CAN'T UPDATE THE TRUSTED HOSTS"
    }
}

function Initialize-DSPRemotePowerShell()
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true, Position=1)]
        [string]$proposedHost
    )

    # Enable PowerShell Remoting
    Enable-PSRemoting -Force

    # Add Hostname to Trusted Hostname
    Add-DSPTrustedHosts $proposedHost

    # Enable CredSSP
    Enable-WSManCredSSP -Role Client -Force -DelegateComputer $proposedHost
}

function Enter-DSPRemoteSession()
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true, Position=0)]
        [string]$Username,

        [Parameter(Mandatory=$true, Position=1)]
        [string]$Password,

        [Parameter(Mandatory=$true, Position=2)]
        [string]$ComputerName 
    )

    [SecureString]$securePassword = $null
    # If password is a path, consider it an encrypted password file
    if(Test-Path $Password)
    {
        $securePassword = Get-Content $Password | ConvertTo-SecureString
    }
    else
    {
        $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
    }

    $cred = New-Object System.Management.Automation.PSCredential ($Username, $securePassword)
    Enter-PSSession ComputerName $ComputerName Credential $cred -Authentication Credssp
}
{'fraction_non_alphanumeric': 0.10218393107593668, 'fraction_numerical': 0.002003606491685033, 'mean_word_length': 2.495798319327731, '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': '2371630', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1490, 'n_words': 318}