0

I recently started to use PowerShell. I've been trying to set up my profile.ps1 to add an alias for vim.

I edited the example profile.ps1 and then moved it to C:\Windows\System32\WindowsPowerShell\v1.0

Which seemed like the correct location as I got the Error stating that running scripts isn't enabled on this machine. So I ran powershell as admin and ran this command:

Set-ExecutionPolicy RemoteSigned

Which got rid of the error message, but my script still seemed to do nothing. It looks like this:

#  Copyright (c) Microsoft Corporation.  All rights reserved.
#  
# THIS SAMPLE CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
# IF THIS CODE AND INFORMATION IS MODIFIED, THE ENTIRE RISK OF USE OR RESULTS IN
# CONNECTION WITH THE USE OF THIS CODE AND INFORMATION REMAINS WITH THE USER.
Write-Host "Hello world"
Set-Alias vim ' C:\Program Files (x86)\Vim\vim74\vim.exe'

Vim still doesn't launch when typing "vim" and "hello world" isn't printed.

user1783150
  • 281
  • 2
  • 6
  • 13
  • Does your script match the output of this command: `Get-Content $PROFILE.AllUsersAllHosts`? – briantist Aug 24 '14 at 07:19
  • I just added it, and unfortunately it did nothing. If I run that command myself it reads the all the commented part of my script. After removing the comments and saving the file, it still reads the comments. So I guess the script was copied to somewhere and I'm editing the wrong one? – user1783150 Aug 24 '14 at 11:12
  • I ran the $profile command, and it gave me the location of the profile.ps1 ...although the location didn't exist(wasn't a hidden folder), so I don't know where the displayed comments came from. Anyway, I created the folder path ( C:\Users\UserNAME\Documents\WindowsPowerShell) and the 'Microsoft.PowerShell_profile.ps1' file, put the commands in it, and all was well. – user1783150 Aug 24 '14 at 11:20
  • Are you using ISE or just a shell? – SomeShinyObject Aug 24 '14 at 12:21
  • Why do this via a powershell alias and not just adding the path to the exe to the path environment variable? It would accomplish the same end. – Joseph Alcorn Aug 24 '14 at 16:47

1 Answers1

1

If you are running the x86 (32-bit) version of PowerShell the path should be C:\Windows\SysWOW64\WindowsPowerShell\v1.0. That is, when a 32-bit process looks for C\Windows\System32 Windows file system virtualization kicks in and redirects it to C:\Windows\SysWOW64.

Or just move the profile to the CurrentUserAllHosts path and you won't have to worry about 32-bit vs 64-bit PowerShell.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369