PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Install-psresource does not install PSGalleryScripts

Open demdante opened this issue 3 years ago • 2 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues.

Steps to reproduce

This issue only affects scripts that are published to the powershell gallery, or psgalleryscripts. For the purposes of this issue, the example script I will use is "Export-PSObjectToINI," You can use "Find-Psresource" to find the "Export-PSObjectToINI" script hosted in the powershell gallery easily: 2022-07-14 15_26_48-Administrator_ Windows PowerShell ISE But when trying to install the script using "install-psresource", the module doesn't return any error or output, which would typically indicate the resource was successfully installed, but attempting to run the script reveals that it was not installed at all:

2022-07-14 15_29_36-Administrator_ Windows PowerShell ISE

This is a problem that needs to be resolved, as the only way to install scripts from the powershell gallery as of now is to import the old version of powershellget and use the "install-script" command.

Expected behavior

The script should have successfully installed on the local machine.

Actual behavior

The script was not installed on the local machine

Error details

No error to be had.

Environment data

get-module powershellget; $PSVersionTable

ModuleType Version    Name                                ExportedCommands                                                                                               
---------- -------    ----                                ----------------                                                                                               
Binary     3.0.14     PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Install-PSResource...}                             

Key   : PSVersion
Value : 5.1.22000.653
Name  : PSVersion


Key   : PSEdition
Value : Desktop
Name  : PSEdition


Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions


Key   : BuildVersion
Value : 10.0.22000.653
Name  : BuildVersion


Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion


Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion


Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion


Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Visuals

No response

demdante avatar Jul 14 '22 19:07 demdante

This is because Install-PSResource isn't adding the install script path to the Path environment variable so it can be ran without prepending the path. In PowerShellGet v2 Install-Script did this by default and now it seems that feature hasn't been added back yet.

You can get around this for now by using.

$env:Path += ";$env:USERPROFILE\Documents\PowerShell\Scripts"

ThomasNieto avatar Jul 18 '22 13:07 ThomasNieto

This is because Install-PSResource isn't adding the install script path to the Path environment variable so it can be ran without prepending the path. In PowerShellGet v2 Install-Script did this by default and now it seems that feature hasn't been added back yet.

You can get around this for now by using.

$env:Path += ";$env:USERPROFILE\Documents\PowerShell\Scripts"

Ahh. I see. You are right. The script is downloaded to the machine in the location you state. Maybe I will take a crack at modifying the "Install-psresource" function so that it adds the script directory to the PATH environment variable if it is not already present to fix that issue. Thanks for your help, but please keep this issue open until the issue has been addressed. Appreciate it.

demdante avatar Jul 19 '22 06:07 demdante

Upon further discussion with the team, we feel it is best for consistency across Windows and Linux to not attempt to modify the user's/machine's environment PATH variable, rather emit a warning indicating how the user could do so and specifying the path with which to do so. The script is still installed successfully, but the user would have to modify the environment PATH variable for discoverability. cc @SydneyhSmith

anamnavi avatar Aug 30 '22 20:08 anamnavi