简体   繁体   English

在Powershell脚本中将路径作为变量传递

[英]passing path as a variable in powershell script

I want to pass path as a varibale(Read-host) in my powershell script. 我想在powershell脚本中将路径作为变量(Read-host)传递。 It is not working giving error as 由于出现错误而无法正常工作

Cannot find path because it does not exist 找不到路径,因为它不存在

My code 我的密码

$a=read-host
$b=read-host
Copy-item $a $b

It's hard for us to really figure out the issue since we don't know exactly what you are typing in. Put the code below into a script to see if the paths are valid or not: 由于我们不知道您到底要输入什么内容,因此我们很难真正找出问题所在。将以下代码放入脚本中,以查看路径是否有效:

$a = Read-Host
$b = Read-Host
'Copying from {0} to {1}' -f $a, $b
Copy-Item $a $b

use the Test-Path it returns a boolean if the path exists 使用测试路径,如果路径存在,则返回布尔值

if(Test-Path $a){
     Copy-Item $a $b
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM