Invoke-WinSCPCommand


Synopsis

Invokes a command on an Active WinSCP Session.


Syntax

Invoke-WinSCPCommand [-WinSCPSession] <Session> [-Command] <String[]> [<CommonParameters>]

Description

Invokes a command against the remote system hosting the FTP/SFTP Service.


Parameters

WinSCPSession <WinSCP.Session>

A valid open WinSCP Session, returned from New-WinSCPSession.

  • Required: True
  • Position: 0
  • Default Value:
  • Accept Pipeline Input: True (ByValue)
  • Accept Wildcard Characters: False

Command <String[]>

Command to execute.

  • Required: True
  • Position: 1
  • Default Value:
  • Accept Pipeline Input: True (ByPropertyName)
  • Accept Wildcard Characters: False

CommonParameters <CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable.


Inputs

WinSCP.Session

  • Represents a session and provides methods for manipulating remote files over SFTP, SCP or FTP session.

String

  • Represents text as a series of Unicode characters.

Outputs

WinSCP.CommandExecutionResult

  • Represents results of Session.ExecuteCommand.

Notes

If the WinSCPSession is piped into this command, the connection will be closed and the object will be disposed upon completion of the command.


Example 1

PS C:\> $credential = Get-Credential
PS C:\> $session = New-WinSCPSession -Credential $credential -Hostname 'myftphost.org' -SshHostKeyFingerprint 'ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx'
PS C:\> Invoke-WinSCPCommand -WinSCPSession $session -Command ("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}" -f $dbUsername, $dbPassword, $tempFilePath)

Fork me on GitHub