This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.

Copy-ToTemp

Synopsis

Copies files to the temp directory on a remote computer. For use with Start-RemoteProcess.

Syntax

  • Copy-ToTemp [-FilePath] [-ComputerName] [-Credential]

Description

Copy-ToTemp copies to a local or remote computer and reports back the location of the file as viewed from the remote computer. Copy-ToTemp can be used in conjunction with the Start-RemoteProcess cmdlet to copy and run executables on remote computers within your network.

Parameters

  • FilePath The exact file name to copy. This parameter does not accept wildcards or directory names. Use Get-ChildItem to pipe files names into this cmdlet if directories or wildcards are required.
  • ComputerName The computer to which files should be copied.
  • Credential The credentials that should be used to make the file copy.

Inputs

Copy-ToTemp accepts the output of the Get-ChildItem cmdlet as an input object. Any files piped from Get-ChildItem into Copy-ToTemp will be copied to the remote computer.

Outputs

Copy-ToTemp returns a Vexasoft.FileCopyInfo object, detailing the file copied, the computer to which it was copied and the path to the new file as seen from the remote computer.

Notes

The cmdlet requires that the Remote Registry and RPC services are started on the computer it is trying to access and that DNS services are available to resolve target host names.

Example 1

This command will copy the local file c:\MyExecutable.exe to the remote computer PC01. The cmdlet will return a FileCopyInfo object containing the path of the file on the remote computer:

C:\PS>Copy-ToTemp -FileName c:\MyExecutable.exe -ComputerName PC01

Example 2

Copy-ToTemp can be used in conjunction with the Start-RemoteProcess cmdlet. This command will copy the local file c:\MyExecutable.exe to the remote computer PC01 and then execute the file on the remote computer.

C:\PS>Copy-ToTemp -FileName c:\MyExecutable.exe -ComputerName PC01 | Start-RemoteProcess

Example 3

Get-ChildItem can be used to build a list of files for Copy-ToTemp to copy. This command will get the names of all the files contained in C:\FilesToCopy using Get-ChildItem, which are then copied to the temp directory on computer PC01 by Copy-ToTemp. A FileCopyInfo object will be returned for each new file on the remote computer:

C:\PS>Get-ChilItem c:\FilesToCopy\*.* | Copy-ToTemp -ComputerName PC01