Before I answer, I must out that you do not want to copy PowerShell module files directly to the path pointed by PsModulePath
. You really want to create a folder inside PSModulePath
and copy the files there instead.
The prefix env
in a Powershell variable indicates an environment variable. $env:PSModulePath
is actually referring to the PSMODULEPATH
environment variable. On the command line, and in batch files, environment variables can be displayed by placing the name between percent symbols. (In fact, you could have displayed this value by typing echo %PSMODULEPATH%
instead.)
To reference the desktop folder, have a look at this answer, which shows you how to use another environment variable, USERPROFILE
.
Therefore, to copy the file from the desktop directory to the path specified in PSModulePath
, you would do this:
COPY "%USERPROFILE%\Desktop\SetConsolePath.psm1" "%PSMODULEPATH%"
And, as I warned earlier, you really should copy the file to a folder underneath PsModulePath
. So what you really want is:
IF NOT EXIST "%PSMODULEPATH%\MyNewFolder" MKDIR "%PSMODULEPATH%\MyNewFolder"
COPY "%USERPROFILE%\Desktop\SetConsolePath.psm1" "%PSMODULEPATH%\MyNewFolder"