0

psftp.exe を呼び出して、ローカル コンピューターからクラウド内のサーバーにファイルを正常に転送できるようにする、動作中の PowerShell スクリプトがあります。PowerShell ISE画面でエラー(私が知る限り、何もプリエンプトしません)がフラッシュされていることを除いて、すべて正常に動作します。

PS D:\PROJECTS\Timekeeping\build_src> D:\PROJECTS\Timekeeping\build_src\mypowershell.ps1
.\psftp.exe : Looking up host "remoteserver"
At D:\PROJECTS\Timekeeping\build_src\mypowershell.ps1:30 char:20
+ ... expression (.\psftp.exe 'remoteserver' -l 'ubuntu' -i key.ppk ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Looking up host "remoteserver":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Connecting to remoteserver port 22
Server version: SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.62
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
ssh-rsa 2048 87:4d:50:8d:09:25:40:78:c2:7b:5c:ef:12:8e:57:7c
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Reading private key file "key.ppk"
Using username "ubuntu".
Offered public key
Offer of public key accepted
Authenticating with public key "imported-openssh-key"
Sent public key signature
Access granted
Opened channel for session
Started a shell/command
Sent EOF message
Server sent command exit status 0
Disconnected: All channels closed
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.
At D:\PROJECTS\Timekeeping\build_src\mypowershell.ps1:30 char:19
+ ... -expression (.\psftp.exe 'remoteserver' -l 'ubuntu' -i key.ppk ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand

セキュリティ上の理由から、サーバーの IP を remoteserver という言葉に置き換え、リモート PC の IP を remotePC に置き換えたことに注意してください。私が使用しているpowershellには、次のコードが含まれています。

#Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
$props = Get-Content D:\PROJECTS\Timekeeping\build_src\branch.txt
$BranchName = $props | select-string 'BranchName' | %{$_.line.split('=')}
$Branch = $BranchName[1]
$datetime2 = get-date -format yyyyMMdd
$datetime = get-date
$Logfile = "D:\PROJECTS\Timekeeping\build_src\logs\$Branch-$datetime2-chronos.log"
Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}
if(!(Test-Connection -ComputerName remotePC -BufferSize 16 -Count 1 -ea 0 -quiet)){ LogWrite "$datetime Biometric Device is turned off!"  }else{ LogWrite "$datetime Biometric Device is turned on!"}
$startdate = get-date -format yyyy-MM-dd
$enddate = get-date -format yyyy-MM-dd
for($i=1;$i -le 1000;$i++){
       $number +="$i,"       
     }
$numlength = $number.Length-1
$x = invoke-webrequest -Uri 'http://remotePC/form/Download?uid=$number"&"sdate=$startdate"&"edate=$enddate' -OutFile D:\PROJECTS\Timekeeping\build_src\logs\$Branch-$datetime2.dat -PassThru
if($x.StatusCode -eq 200){
    LogWrite "$datetime Timesheet successfully retrieved. Response code: $($x.StatusCode)"
}else{
    LogWrite "$datetime Error retrieving timesheet. Response code: $($x.StatusCode)"
}
#invoke-expression .\psftp.exe -i key.ppk ubuntu@remoteserver -be b sftpcommands.txt > D:\PROJECTS\Timekeeping\build_src\logs\sftp-log.log 2>$null
#Write-Host "done"

invoke-expression (.\psftp.exe 'remoteserver' -l 'ubuntu' -i key.ppk -v -b 'sftpcommands.txt' > 'D:\PROJECTS\Timekeeping\build_src\logs\sftp-log.log') 2> $null
4

0 に答える 0