New-WinSCPItem


Synopsis

Creates a new object in an active WinSCP Session.


Syntax

New-WinSCPItem [-WinSCPSession] <Session> [[-Path] <String[]>] [[-Name] <String>] [[-ItemType] <String>] [[-Value] <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

After establishing a valid WinSCP Session, this function can be used to create a new object on the remote host.


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[]>

Specifies a path to one or more locations. Wildcards are permitted. The default location is the home directory of the user making the connection.

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

Name <String>

The name of the new item to be created. This can be omitted if full path is used to the new item.

  • Required: False
  • Position: 2
  • Default Value:
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

ItemType <String>

The type of object to be created, IE: File, Directory.

  • Required: False
  • Position: 3
  • Default Value: File
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

Value <String>

Initial value to add to the object being created.

  • Required: False
  • Position: 4
  • Default Value:
  • Accept Pipeline Input: False
  • Accept Wildcard Characters: False

Force <SwitchParameter>

Will overwrite and existing item of the same name.

  • Required: False
  • Position: Named
  • Default Value:
  • Accept Pipeline Input: False
  • 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.

System.String

  • Represents text as a series of Unicode characters.

Outputs

WinSCP.RemoteFileInfo

  • Represents data about remote file.

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 | New-WinSCPItem-Path '/rDir/rSubDir' -ItemType Directory

   Directory: /rDir/

FileType             LastWriteTime     Length Name
--------             -------------     ------ ----
D             1/1/2015 12:00:00 AM          0 /rSubDir

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:\> New-WinSCPItem -WinSCPSession $session -Path './rDir' -Name 'rTextFile.txt' -ItemType File -Value 'Hello World!'
   
   Directory: /rDir

FileType             LastWriteTime     Length Name
--------             -------------     ------ ----
-             1/1/2015 12:00:00 AM         12 /rTextFile.txt

Fork me on GitHub