How to start powershell
I often starts powershell.exe from an explorer instead of command prompt because it looks better than command prompt and powershell command is available. As you may know applications can be started from the directory where you currently open in windows explorer by specifying the command into directory path display area.
Long directory path problem
But when you input “powershell” into the directory path display area it is started with the default execution policy setting which doesn’t allow you to load powershell script. This got me irritated because I wanted to load powershell script which includes a function to change a way to show directory path. Isn’t it hard to see if the directory path and your command are long?
I wanted to make the directory path short!! When powershell starts it tries to load “DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1” but powershell cannot load this file because of execution policy!!
I don’t want to change the default setting because of security but I want to change it when I want to start powershell from windows explorer…
Solution
Add a command file
Add the Path to the file
The directory path is not included into a environment path. Therefore, windows cannot find the file even if you input the command name into directory path display area.“C:commands” must be added to environment variable. The step is following.
- Open Control panel > System > Advanced system settings
- Open Environment setting
- Click Path variable and click edit
- Add “C:commands“
- Click OK
Try to start
Open a directory with windows explorer and input “ps” and tap Enter key. The error message has gone because powershell is executed by ps.bat which set execution policy to RemoteSigned.
How to show current directory name
“<users>DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1”
I defined following code. This shows the current directory name.
function prompt() {
(Split-Path (Get-Location) -Leaf) + " > "
}
Comments