0

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

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

use the Test-Path it returns a boolean if the path exists

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.