Test-WinSCPPath


Synopsis

Test if a remote object exists.


Syntax

Test-WinSCPPath [-WinSCPSession] <Session> [-Path] <String[]> [<CommonParameters>]

Description

After creating a valid WinSCP Session, this function can be used to test if a directory or file exists on the remote source.


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

Path <String[]>

Full path to the remote object.

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

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.

System.String

  • Represents text as a series of Unicode characters.

Outputs

System.Boolean

  • Represents a Boolean (true or false) value.

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:\> New-WinSCPSession -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:USERNAME, (New-Object -TypeName System.Security.SecureString)) -HostName $env:COMPUTERNAME -Protocol Ftp | Test-WinSCPPath -Path '/rDir/rSubDir'

True

Example 2

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:\> Test-WinSCPPath -WinSCPSession $session -Path '/rDir/NoPath'

False

Fork me on GitHub