PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
486 stars 92 forks source link

Adding the Parameter -Scope with Values for AllUsers, CurrentUser to Register-PSResourceRepository #1670

Closed tinuwalther closed 1 month ago

tinuwalther commented 3 months ago

Summary of the new feature / enhancement

As a user of the PSResourceGet module, I would like to have the option to register the repository for all users or for the current user. Currently it is not possible to register the repository for all users and we need to implement a workaround to do this for each newly logged in user.

Workaround: Copy the "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml" of a user to each newly logged in users AppData-Folder.

Proposed technical implementation details (optional)

It should be possible to use the Register-PSResourceRepository as in the following example:

[PSCredential]$cred = Get-Credential -Message 'Enter your credentials for the repository to register'

$parameters = @{
    Name = 'nexusNugetRepo'
    Uri  = 'http://localhost:8081/repository/PSModules/'
    Trusted = $true
    Priority = 50
    Credential = $cred
    Scope = 'AllUser' # or 'CurrentUser'
} 
Register-PSResourceRepository @parameters 
Stephanevg commented 3 months ago

Ideally / alternatively, it would be great to be able to declare the uri's somewhere 'external' as of the PsRessourceGet module / powershell prompt. I am thinking of a key registry / a Json file or something of that nature. This would really help the management side of things, in Windows managed environements, where we could potentially deploy these Uri's per GPO, on other Os's tools such as Ansible could then set for mass management.

ntatschner commented 2 months ago

This would be really useful; At the moment if you want all users that log in to that device to get the resource you can add a default startup script to the Default user. I'm planning on just deploying it using Intune as a Powershell script, in the script I register it as normal but then loop through all LOCALAPPDATA folders and copy the content I generate below.

Get the specific resource i want to export to all users using:

$PSResource = (Import-Clixml -Path "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml").Item("NAMEOFRESOURCE")
$PSResource | Export-Clixml -Path .\ReadyToCopyResource.xml
SydneyhSmith commented 1 month ago

Thanks! This looks similar to #84 #616

tinuwalther commented 1 month ago

Hi @SydneyhSmith. My part is covered with the requests #84 #616, but @Stephanevg's part with saving the URL in the registry for Windows and in a file for Linux is missing. Can you still include that part?

microsoft-github-policy-service[bot] commented 1 month ago

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.