Error with PowerShell command for copying file to remote server with credential

吃可爱长大的小学妹 提交于 2021-01-27 11:25:03

问题


PS C:\Windows\system32> Copy-Item -ToSession $s C:\Programs\temp\test.txt -Destination C:\Programs\temp\test.txt

Copy-Item : A parameter cannot be found that matches parameter name 'ToSession'. At line:1 char:11

  • Copy-Item -ToSession $s C:\Programs\temp\test.txt -Destination C:\Programs\temp\ ...
  • ~~~~~~~~~~
    • CategoryInfo : InvalidArgument: (:) [Copy-Item], ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

回答1:


As it is noted in the change list of PoSh V5 here and you tagged your question with V4 the simple answer is probably your version's Copy-Item cmdlet does not provide that parameter

Copy-Item now lets you copy files or folders from one Windows PowerShell session to another, meaning that you can copy files to sessions that are connected to remote computers, (including computers that are running Nano Server, and thus have no other interface). To copy files, specify PSSession IDs as the value of the new -FromSession and -ToSession parameters, and add –Path and –Destination to specify origin path and destination, respectively. For example, Copy-Item -Path c:\myFile.txt -ToSession $s -Destination d:\destinationFolder.



来源:https://stackoverflow.com/questions/39224609/error-with-powershell-command-for-copying-file-to-remote-server-with-credential

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!