Move-Item : Cannot find path

Hi Guys.

I have a simple copy-item job that is moving a folder matching the $Username viable from one location to another. I am then trying to move a folder from one location to another on the copied data but i am seeing the error below. If I change the $UserName to the actual folder name the move is fine. Is there a reason it does not like the variable?

Move-Item : Cannot find path ‘D:\Migration-Folder$UserName\Documents\My Pictures’ because it does not
exist.

$UserName = "TESTUSER"

Copy-Item -Recurse -Path U:\$UserName D:\Migration-Folder -Force

Move-Item -path 'D:\Migration-Folder\$UserName\Documents\My Pictures 'D:\Migration-Folder\$UserName

Ok so sticking the folders in a variable has move the move item work. Curious to know what it is about the move-item through as its the first time i have put a variable in that command.

$UserName = "TESTUSER"
$MyPictures = "D:\Migration-Folder\$UserName\Documents\My Pictures"
$DestinationFolder = "D:\Migration-Folder\$UserName"

Copy-Item -Recurse -Path U:\$UserName D:\Migration-Folder -Force

Move-Item -path $MyPictures $DestinationFolder 

Variables will not be substituted with their content if you enclose them in single quotes. Use double quotes instead. :wink:

Hi,
The path should be in quotation marks, single or double depending on whether it is static or dynamic - with a variable.
Why should the path be in quotation marks? mainly because of spaces in the folder name, e.g. “My Pictures”

What is the difference between single and double quotation marks:

Thank you for the explanation