Private/Install-specModuleFromBlob.ps1

function Install-specModuleFromBlob {
    <#
.SYNOPSIS
Downloads and installs a PowerShell module from Azure Blob Storage.
 
.DESCRIPTION
Downloads the .psm1 and .psd1 files for the specified module from given URLs
and places them in the specified install path. Throws an exception if the
download or installation fails.
 
.PARAMETER ModuleName
The name of the module to install.
 
.PARAMETER InstallPath
The directory path to install the module into.
 
.PARAMETER Psm1Url
The URL to the module’s .psm1 file in Blob Storage.
 
.PARAMETER Psd1Url
The URL to the module’s .psd1 file in Blob Storage.
 
.EXAMPLE
Install-specModuleFromBlob -ModuleName 'MyModule' `
    -InstallPath 'C:\Modules\MyModule' `
    -Psm1Url 'https://storage.blob.core.windows.net/container/MyModule.psm1?SAS' `
    -Psd1Url 'https://storage.blob.core.windows.net/container/MyModule.psd1?SAS'
 
.NOTES
Author: owen.heaume
Version: 1.0 - Initial release
#>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$ModuleName,

        [Parameter(Mandatory)]
        [string]$InstallPath,

        [Parameter(Mandatory)]
        [string]$Psm1Url,

        [Parameter(Mandatory)]
        [string]$Psd1Url
    )

    try {
        Write-Verbose "Downloading module '$ModuleName' from Blob Storage to '$InstallPath'..."

        # Ensure the install path exists
        New-Item -ItemType Directory -Force -Path $InstallPath -ErrorAction Stop | Out-Null

        # Download module files
        Invoke-WebRequest -Uri $Psm1Url -OutFile (Join-Path $InstallPath "$ModuleName.psm1") -ea Stop
        Invoke-WebRequest -Uri $Psd1Url -OutFile (Join-Path $InstallPath "$ModuleName.psd1") -ea Stop

        Write-Verbose "Module '$ModuleName' installed/updated successfully at '$InstallPath'."

        return $true
    } catch {
        Write-Error "Failed to install module '$ModuleName': $($_.Exception.Message)"
    }
}