I am new to Windows PowerShell. Basically, before running a script in command line, I would like to set the $HOME environment variable to a different directory.
I don't really want to change the system $HOME variable that may affect other software. I just want this change to affect the script I am running or just the shell I am using.
I don't recommend changing $HOME but if you must:
Set-Variable -Name Home -Value C:\Windows -Force
This will impact the shell/session and every script that runs in this shell. If doing this for a script you might think about setting it back after the script finishes eg:
$oldHome = $Home
Set-Variable -Name Home -Value C:\windows -Force
...
Set-Variable -Name Home -Value $oldHome -Force
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.