copy-item where file name is the computer hostname

前端 未结 3 1841
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 17:32

Having what seems to be a basic problem in Powershell. I am doing a simple copy-item script from a UNC share to the local C:\\ drive. Here is my code:



        
3条回答
  •  失恋的感觉
    2021-01-14 18:13

    Single quoted strings will not expand variables. You need a double quoted string e.g.:

    Copy-Item "\\server\share\$hostname.txt" C:\
    

    And in general, you don't need to quote string arguments to a PowerShell command unless you need variable expansion or there's a space in the string.

提交回复
热议问题