SynopsisCopies files to the temp directory on a remote computer. For use with Start-RemoteProcess.
- Copy-ToTemp [-FilePath] [-ComputerName] [-Credential]
DescriptionCopy-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.
- 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.
InputsCopy-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.
OutputsCopy-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.
NotesThe 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 1This 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 2Copy-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 3Get-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