Skip to content

Powershell module with Module & Repository Management #5102

@AniTexs

Description

@AniTexs

Summary of the new feature / enhancement

This would be wonderful to be able to update modules from a script using the PSU Module Management.
Functions:

  • Get-PSUInstalledModule
  • Get-PSURepositories
  • Find-PSUModule
  • Update-PSUModule
  • Install-PSUModule
  • etc

This would bring amazing enhancement for me with several custom modules from my private repo.
This is would also bring joy for others.

Proposed technical implementation details (optional)

Cmdlets/Functions like:

function Get-PSUInstalledModule {
    <#
.SYNOPSIS
Get installed Modules

.PARAMETER Name

.PARAMETER ListAvailable
Switch parameter which list all versions and modules.

.PARAMETER UniversalRepository
Switch parameter to only list installed modules under Powershell Universal
#>
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, Position = 0,ParameterSetName = 'Default')]
        [Parameter(Mandatory = $false, Position = 0,ParameterSetName = 'Universal')]
        [ValidateNotNullOrEmpty()]
        [string]$Name,
        [Parameter(Mandatory = $false, Position = 0,ParameterSetName = 'Default')]
        [Parameter(Mandatory = $false, Position = 1,ParameterSetName = 'Universal')]
        [switch]$ListAvailable,
        [Parameter(Mandatory = $true, Position = 2,ParameterSetName = 'Universal')]
        [switch]$UniversalRepository
    )
    $params = @{
        Name = $Name
        ErrorAction = 'SilentlyContinue'
    }
    if($UniversalRepository.IsPresent){
        $Path = "C:\ProgramData\UniversalAutomation\Repository\Modules\"
        if([String]::IsNullOrEmpty($Name)){
            $Path = $Path + "*"
        } else {
            $Path = $Path + $Name
        }
        $params.Name = $Path
        $params.ListAvailable = $true
    }
    if($ListAvailable.IsPresent){
        $params.ListAvailable = $true
    }
    $Modules = Get-Module @params
    if(-not $ListAvailable.IsPresent){
        # If ListAvailable is $false, we need to ensure we only return unique modules and the latest version
        $Modules = $Modules | Group-Object Name | ForEach-Object {
            $_.Group | Sort-Object Version -Descending | Select-Object -First 1
        }
        $Modules = $Modules | Select-Object -Unique Name, Version, Path
    }
    $Modules
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions