functions/Copy-ArtifactToSession.ps1

function Copy-ArtifactToSession {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)] 
        [String]
        $SourceFolderPath,
        [Parameter(Mandatory = $true)] 
        [String]
        $TargetFolderPath,
        [Parameter(Mandatory = $true)] 
        $Session
    )
    
    begin {
        Write-Information "Begin copying $SourceFolderPath to $TargetFolderPath"
    }
    
    process {
        Invoke-Command -Session $Session -ScriptBlock {
            param($TargetFolderPath) 
            if (Test-Path($TargetFolderPath)) { 
                Remove-Item $TargetFolderPath -Recurse -Force 
            } 
        } -ArgumentList $TargetFolderPath
    
        Copy-Item -Path $SourceFolderPath -Destination $TargetFolderPath -ToSession $Session -Recurse -Force -Verbose
    }
    
    end {
        Write-Information "End copying $SourceFolderPath to $TargetFolderPath"
    }
}