So, warning, this is probably a really newbie questions, so apologies in advance.
I'm starting to learn Powershell and one of the first things I want to do, is just make a directory & copy a file to it.
Now, if I use the following commands in a CMD window, they work perfectly.
mkdir %HOMEPATH%\test
cp test.txt %HOMEPATH%\test
However, when I put them into a .ps1 file and execute it, I get an error saying the directory could not be found etc (see below)
Copy-Item : Could not find a part of the path 'C:\Chef\windowsdevbox-master\%HOMEPATH%\.berkshelf'
Now, I got told that this is because I need to put CMD before each command. I ran this, with the CMD in front of each one and the error disappeared and instead I was presented with the "Home text" for CMD and the script finished.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
However, the folder was not created and the file was not copied over.
I just wondered what I need to do to get this to work.
get-childitem variable:in powershell.$HOMEinstead of%HOMEPATH%(though those aren't quite identical I think), etc. The problem with your sample commands is that%VAR%isn't a powershell variable.