As you are using PowerShell, then you better use WinSCP .NET assembly like:
Though you actually want to call
$files =
$session.EnumerateRemoteFiles(
$remotePath, $mask, [WinSCP.EnumerationOptions]::AllDirectories)
foreach ($fileInfo in $files)
{
Write-Host "Deleting $($fileInfo.FullName) ..."
$session.RemoveFile($fileInfo.FullName)
}
Though you actually want to call
Session.GetFileToDirectory
with remove = $True
.