Closed sdg002 closed 2 years ago
@alerickson @anamnavi Does PowerShellGet v3 allows the user to specify where to install a module? If not, maybe you want to consider doing so.
@daxian-dbw v3 does allow users to specify where to install a module, in two different ways:
1) The user can modify the $env:PSModulePath
and v3 will prioritize these paths over the default PowerShell paths
2) The user can run Save-PSResource <ModuleName> -IncludeXML -Path <InstallLocation>
@sdg002 are you still blocked with this issue? Do you need assistance with it or are just filing a report?
PSv2 can do Save-Module
which is similar to Save-PSResource
.
The user can modify the
$env:PSModulePath
and v3 will prioritize these paths over the default PowerShell paths
When $env:PSModulePath
is changed to not include C:\Users\johndoe\Documents\PowerShell\Modules
, where will the module be installed when using -Scope CurrentUser
in v3?
It'll look at whatever paths are in $env:PSModulePath
and find the next available path that ends in \Modules
. If it doesn't find any appropriate paths there, it'll install to C:\Users\johndoe\Documents\PowerShell\Modules
It sounds like that's what @sdg002 was asking :)
Thank you @alerickson and @daxian-dbw for taking time to look into this.
Yes - I managed to find a work around using a combination of Find-Module
, Save-Module
and alterations to $env:PSModulePath
.
I will document the steps here , if in case somebody faces the same predicament as I did.
No local admin rights to the workstation as per Corporate policies
The MyDocuments
special folder C:\Users\johndoe\Documents
has a strict Anti-Virus policy which disallows the Operating System from running any executable file, .VBS script, .PS script or load any .DLL from the MyDocuments
folder
To make matters more interesting the MyDocuments
special folder C:\Users\johndoe\Documents
is actually mapped to a Distributed File System. (to allow hot desking and working via VDI)
The Install-Module
cmdlet fails when I used -Scope AllUsers
because of lack of admin rights
The Install-Module
cmdlet appears to succeed partially when I used -Scope CurrentUser
. The assemblies get installed to C:\Users\johndoe\Documents\PowerShell\Modules
folder as far as it can. When there is a chaim of dependent modules to be installed, then there is an abrupt failure down stream.
Due to the strict AV policy on the MyDocuments
folder, PowerShell is unable to load any cmdlet. E.g. Even if the DLLs of Az-Accounts
were available in MyDocuments
, then I would not be able to find or use the cmdlet Get-AzContext
. Even Find-InstalledModule
would not list Az.Accounts
(the owner module of Get-AzContext)
The error message is very fuzzy when I try to invoke a cmdlet. With the -verbose
flag, it simply says could not load the module ....
. A sensible error message would have saved me lots of hours and chasing around.
Use has no rights to edit environment variables using the Control Panel --> System user interface. This makes editing any user specific environment variables onerous. Has to be scripted via PowerShell or Python.
C:\Users\johndoe\MyPowerShellModules
PWSH
. Navigate to the above folder.$env:PSModulePath
such that the path C:\Users\johndoe\Documents
is removed from it. And, ensure that the path C:\Users\johndoe\MyPowerShellModules
is appended to $env:PSModulePath
Find-Module
and Save-Module
install your modules to this folder. You should see DLLs getting downloaded in the directory MyPowerShellModules
, $env:PSModulePath
such that the path C:\Users\johndoe\Documents
is removed from it. And, ensure that the path C:\Users\johndoe\MyPowerShellModules
is appended to $env:PSModulePath
PowerShell should clearly state attempting to load DLL xyz.dll from path c:\blah1\blah2 and failed ...
. The mentioning of the absolute path makes it very explicit for me.
venv
or virtual environment
system which allows PIP install to any folder of choicenpm install
to a local folder and do what it needs to do.This is my motivation for the suggestion that PWSH should be
AllUsers
and CurrentUser
scope. packages.json
of NPM
and requirements.txt
of python virtual environment and thus provide true side-by-side co-existence of modules with different versions)MyDocuments
and AV prevent this script from getting loadedPWSH is such a great scripting tool. This is one of the best things to come out of Micrsoft. I propose we make it even better. With the backing of .NET, sky is the limit for PWSH.
Thanks
Summary of the new feature / enhancement
As an user in a very restricted environment I cannot use PowerShell Core V7 on Windows 10 because of the following reasons acting simultaneously:
Install-Module -Scope CurrentUser -Name SomeModule
) to theC:\Users\johndoe\Documents\PowerShell\Modules
regardless of the$env:PSModulePath
Documents
folder hierarchy has a corporate Anti-Virus policy and does not allow any DLL/EXE/.BAT/PS1/.VBS file to be executed. Therefore,install-module
appears to work, but PWSH is unable to load any module.All the above make it impossible to use any module thereby rendering PowerShell Core almost useless in my current work environment.
What workarounds did I try?
C:\Users\johndoe\mywork001
, outside ofDocuments
hierarchy to bypass Anti-Virus.$env:PSModulePath
in the vain hope that PWSH would start using the aforementioned folder for installing modules.powershell.config.json
as per this link , but this too did not workPossible solution - inspired by NPM
Taking inspiration from Node Package Manager works (NPM) , PowerShell Core should not rely on a hard wired set of folder(s) for installing modules. Instead, it should be allowed to use the current working directory. Think of a
package.json
in the case of NPM and the JavaScript modules get installed in thenode_modules
sub-folder of the current working directoryPossible solution - inspired by powershell.config.json
I should be able to create a powershell.config.json in any folder
c:\users\johndoe\mywork001\
and able to runpwsh.exe
located in another folder by specifying the absolute path to the powershel.config.json as a command line argument. The PWSH.exe instance should follow the directions of the configuration file and install modules accordinglyOverarching idea
Make PWSH free from the shackles of CurrentUser and AllUsers scope. The CurrentUser/AllUser could still be retained as good to have options. I should be able to run side by side copies of PWSH using different versions of Modules , just like XCOPY of .NET or NODE.JS.
Proposed technical implementation details (optional)
Installing a module locally could look something like the following:
If this were NPM, then you would do the following:
You will see the entry of
SqlServer
getting added topackage.json
and the Jascript code downloaded tonode_modules
folder.The benefit of
package.json
is the ability to have SCM on your environment. You can reproduce your working folder by simply doing anpm install
and all the packages listed inpackage.json
will get downloaded with the right versions.No response