Powershell file is not digitally signed

A powershell profile which I have happily used for over a year suddenly turned on me today. Normally when I open up the command prompt, it would kick off powershell and which would then load posh-git using a powershell profile but instead of the super nice git prompt, I received the following error:

File cannot be loaded. The file \\somenetworkserver\myhomefolder\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 is not digitally signed.

The file was created by me initially so digital signature has no relevance here. I tried to resolve this issue by tinkering with Set-ExecutionPolicy Unrestricted and Set-ExecutionPolicy ByPass, needless to say, they didn’t work. If it was that simple, I wouldn’t be writing this post.

Luckily I found this blog article which pointed me in the right direction: http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/29/how-to-run-powershell-scripts-from-a-shared-directory.aspx

By default, computers running Windows Server include UNC paths in the Internet security zone. Windows PowerShell is actually responding to the security zone when it throws the error for the UNC paths.

Alright, we are getting somewhere, since the powershell profile sits in a network share, this must be it.

Fix Attempt No. 1
OK, let’s see if I can add the UNC to the intranet zone. Bad news! The setting was locked down by Group Policy. Basically any fixes that need to manipulate group policy is out of question.

 internet_options

OK, don’t panic, think. So I cannot place the profile file on the network share, what if I move it to a local drive? Bingo.

Fix Attempt No. 2
After wasting a good 10 minutes on Stack Overflow I conceded that it is not possible to move the profile files as they can only be created in their default locations. Wait a minute, they? files? How many profile files are there? I then fired up get-help about_profiles and like a compass it led me to the solution.

Fix Attempt No. 3
Apparently $profile.AllUsersAllHosts is located in $PsHome and thank god it is on the local drive: $PsHome = C:\Windows\System32\WindowsPowerShell\v1.0

At this point, I had reached enlightenment. I joyfully carried out the following steps and my profile was once again happily loading posh-git on start up:

  1. Create a new profile
    1.  new-item –type file –path $profile.AllUsersAllHosts –force
      1. Small hiccup here. I was looking for Microsoft.PowerShell_profile.ps1 after running the command but the file was actually named profile.ps1
  2. Move content from Microsoft.PowerShell_profile.ps1 to profile.ps1
  3. Remove Microsoft.PowerShell_profile.ps1 from the network share.