Reputation: 1
I want to pass path as a varibale(Read-host) in my powershell script. 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
Upvotes: 0
Views: 460
Reputation: 21
use the Test-Path it returns a boolean if the path exists
if(Test-Path $a){
Copy-Item $a $b
}
Upvotes: 0
Reputation: 37830
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
Upvotes: 1