Files
2026-07-07 15:39:46 +08:00

52 lines
1.3 KiB
PowerShell

function Invoke-RemoteCmd {
param(
[Parameter(Mandatory = $true)]
[string]$Command
)
Write-Host "=====================开始执行[$Command]============================"
$remoteCmd = "cmd.exe /c ""chcp 65001>nul && $Command"""
& $plink `
-ssh `
-v `
-batch `
-pw $password `
$userHost `
$remoteCmd
Write-Host "=====================结束执行[$LASTEXITCODE][$Command]============================"
return $LASTEXITCODE
}
function Invoke-RemoteCopy {
param(
[Parameter(Mandatory = $true)]
[string]$Source,
[Parameter(Mandatory = $true)]
[string]$Destination
)
Write-Host "=====================开始执行[$Source==>$Destination]============================"
& $global:pscp `
-scp `
-pw $global:password `
-batch `
$Source `
$Destination
Write-Host "=====================结束执行[$LASTEXITCODE][$Source==>$Destination]============================"
$ret = $LASTEXITCODE
if ($ret -ne 0) {
Write-Warning "pscp failed, fallback to plink..."
& $global:plink `
-ssh `
-v `
-batch `
-pw $global:password `
$global:userHost
return $LASTEXITCODE
}
Write-Host "copy ok"
return 0
}