lukesampson / pshazz

Give your powershell some pizazz.
The Unlicense
575 stars 40 forks source link

Problem accessing PowerShell profile #77

Open raikesy opened 5 years ago

raikesy commented 5 years ago

NB I don't believe this issue is related to #73 Using PowerShell Core 6.1.1

I have a profile in the default location C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 with a few lines in it. Running scoop install pshazz fails and gives the following output:

Installing 'pshazz' (0.2019.01.12) [64bit]
Loading f40bfabb011e38215f66610e5dce432fa67ba393.zip from cache
Checking hash of f40bfabb011e38215f66610e5dce432fa67ba393.zip ... ok.
Extracting f40bfabb011e38215f66610e5dce432fa67ba393.zip ... done.
adding pshazz to your powershell profile
out-file : Access to the path 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' is denied.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\bin\install.ps1:16 char:2
+     $new_profile > $profile
+     ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.OutFileCommand

           _                   _
 _ __  ___| |__   __ _ _______| |
| '_ \/ __| '_ \ / _` |_  /_  / |
| |_) \__ \ | | | (_| |/ / / /|_|
| .__/|___/_| |_|\__,_/___/___(_)
|_|

resolve-path : Cannot find path 'C:\Users\jzrai\scoop\apps\pshazz\current\bin\pshazz.ps1' because it does not exist.
At C:\Users\jzrai\scoop\apps\scoop\current\libexec\scoop-which.ps1:29 char:20
+ ...       $exepath = resolve-path (join-path (split-path $path) $exepath)
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\jzrai\...\bin\pshazz.ps1:String) [Resolve-Path], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand

Split-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\plugins\ssh.ps1:209 char:60
+ ... azzPath = Resolve-Path (Split-Path (Split-Path (scoop which pshazz)))
+                                                    ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.SplitPathCommand

Linking ~\scoop\apps\pshazz\current => ~\scoop\apps\pshazz\0.2019.01.12
Creating shim for 'pshazz'.
Creating shim for 'askpass'.
Can't shim 'libexec\askpass.exe': File doesn't exist.

It seems to be permissions related but running Get-Acl on the profile file gives the same result as on any other file that I can access without problem.

Then I deleted the profile file and re-ran the installer so it could create a fresh profile but this also failed, giving output:

Installing 'pshazz' (0.2019.01.12) [64bit]
Loading f40bfabb011e38215f66610e5dce432fa67ba393.zip from cache
Checking hash of f40bfabb011e38215f66610e5dce432fa67ba393.zip ... ok.
Extracting f40bfabb011e38215f66610e5dce432fa67ba393.zip ... done.
out-file : Could not find file 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\bin\install.ps1:4 char:2
+     '' > $profile
+     ~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (:) [Out-File], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

gc : Cannot find path 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' because it does not exist.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\bin\install.ps1:10 char:9
+ $text = gc $profile
+         ~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\jzrai\...ell_profile.ps1:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

adding pshazz to your powershell profile
out-file : Could not find file 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\bin\install.ps1:16 char:2
+     $new_profile > $profile
+     ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (:) [Out-File], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

           _                   _
 _ __  ___| |__   __ _ _______| |
| '_ \/ __| '_ \ / _` |_  /_  / |
| |_) \__ \ | | | (_| |/ / / /|_|
| .__/|___/_| |_|\__,_/___/___(_)
|_|

resolve-path : Cannot find path 'C:\Users\jzrai\scoop\apps\pshazz\current\bin\pshazz.ps1' because it does not exist.
At C:\Users\jzrai\scoop\apps\scoop\current\libexec\scoop-which.ps1:29 char:20
+ ...       $exepath = resolve-path (join-path (split-path $path) $exepath)
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\jzrai\...\bin\pshazz.ps1:String) [Resolve-Path], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand

Split-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.12\plugins\ssh.ps1:209 char:60
+ ... azzPath = Resolve-Path (Split-Path (Split-Path (scoop which pshazz)))
+                                                    ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.SplitPathCommand

Linking ~\scoop\apps\pshazz\current => ~\scoop\apps\pshazz\0.2019.01.12
Creating shim for 'pshazz'.
Creating shim for 'askpass'.
Can't shim 'libexec\askpass.exe': File doesn't exist.

This seems like something weird with my environment but I have no idea what's causing it and even so I think the installation would be better off failing gracefully rather than "semi-installing" as currently occurs (runs pshazz in current window but obviously on next startup)

chawyehsu commented 5 years ago

Could you try to install the updated one 0.2019.01.13 to see if it works?

raikesy commented 5 years ago

@h404bi Identical results with 0.2019.01.13

Edit: Wait sorry, not identical.

Output with existing $profile (but no pshazz init line):

Updating Scoop...
Updating 'extras' bucket...
Updating 'java' bucket...
Updating 'retools' bucket...
Scoop was updated successfully!
WARN  Scoop uses 'aria2c' for multi-connection downloads.
WARN  Should it cause issues, run 'scoop config aria2-enabled false' to disable it.
Installing 'pshazz' (0.2019.01.13) [64bit]
Loading e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip from cache.
Checking hash of e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip ... ok.
Extracting e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip ... done.
adding pshazz to your powershell profile
out-file : Access to the path 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' is denied.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.13\bin\install.ps1:16 char:2
+     $new_profile > $profile
+     ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.OutFileCommand

           _                   _
 _ __  ___| |__   __ _ _______| |
| '_ \/ __| '_ \ / _` |_  /_  / |
| |_) \__ \ | | | (_| |/ / / /|_|
| .__/|___/_| |_|\__,_/___/___(_)
|_|

Linking ~\scoop\apps\pshazz\current => ~\scoop\apps\pshazz\0.2019.01.13
Creating shim for 'pshazz'.
'pshazz' (0.2019.01.13) was installed successfully!

Output with no $profile:

Updating Scoop...
Updating 'extras' bucket...
Updating 'java' bucket...
Updating 'retools' bucket...
Scoop was updated successfully!
WARN  Scoop uses 'aria2c' for multi-connection downloads.
WARN  Should it cause issues, run 'scoop config aria2-enabled false' to disable it.
Installing 'pshazz' (0.2019.01.13) [64bit]
Loading e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip from cache.
Checking hash of e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip ... ok.
Extracting e0cbd3fe165ea194a0d2e58001306b9cab22aa56.zip ... done.
out-file : Could not find file 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.13\bin\install.ps1:4 char:2
+     '' > $profile
+     ~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (:) [Out-File], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

gc : Cannot find path 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' because it does not exist.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.13\bin\install.ps1:10 char:9
+ $text = gc $profile
+         ~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\jzrai\...ell_profile.ps1:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

adding pshazz to your powershell profile
out-file : Could not find file 'C:\Users\jzrai\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.
At C:\Users\jzrai\scoop\apps\pshazz\0.2019.01.13\bin\install.ps1:16 char:2
+     $new_profile > $profile
+     ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (:) [Out-File], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

           _                   _
 _ __  ___| |__   __ _ _______| |
| '_ \/ __| '_ \ / _` |_  /_  / |
| |_) \__ \ | | | (_| |/ / / /|_|
| .__/|___/_| |_|\__,_/___/___(_)
|_|

Linking ~\scoop\apps\pshazz\current => ~\scoop\apps\pshazz\0.2019.01.13
Creating shim for 'pshazz'.
'pshazz' (0.2019.01.13) was installed successfully!
chawyehsu commented 5 years ago

Looks like your $PROFILE is read-only and cannot be rewritten.

raikesy commented 5 years ago

Yes but even if I delete it, pshazz can't create a new one, so it can't be to do with the permissions on the file, because the file has been deleted.

dromonaco commented 5 years ago

I got the same error and, for me, Windows Defender was blocking access. This is in my event log:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe has been blocked from modifying %userprofile%\OneDrive\Documents\WindowsPowerShell by Controlled Folder Access.

I was able to get by this by turning Windows Defender real time protection off, running scoop install pshazz and then turning Windows Defender real time protection back on again.

It should also work if you add C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe to the list of apps that have Controlled Folder Access, but I don't know what the security implications would be. I'm guessing MS would have already done this if they thought it was safe.