Skip to content
Import PowerShell Module from GitHub – Single-File Method

Import PowerShell Module from GitHub – Single-File Method

Import PowerShell Module from GitHub (Single-File Method)

A clean, no-install, session-only way to load a PowerShell module directly from a GitHub-hosted .psm1 file.

Ideal for jump boxes, containers, servers, or any temporary/ad-hoc usage.

script to use:

1
Import-Module -Name ([scriptblock]::Create((Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1' -UseBasicParsing).Content))

When to Use This Method

  • Your module is one single .psm1 file
  • You want zero disk footprint after the session ends
  • Quick loading on any machine with internet
  • No permanent module installation (Install-Module, PSResourceGet, etc.)

Works on Windows PowerShell 5.1 and PowerShell 7+.

Prerequisites

  • Internet access
  • Invoke-WebRequest (built-in)
  • Execution policy allowing downloaded scripts (RemoteSigned or Unrestricted are common)

Step-by-Step Setup

1. Prepare Your GitHub Repo

Place your module code in a single file, e.g. MyTools.psm1.

Example repo structure: yourusername/ └── MyTools/ └── MyTools.psm1

Push to the default branch (usually main).

2. Get the Raw URL

Navigate to your .psm1 file on GitHub → click Raw.

Example:

https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1

3. Import One-Liners

Recommended (clean & safe):

1
Import-Module -Name ([scriptblock]::Create((Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1' -UseBasicParsing).Content))

Even more secure (with TLS + timeout):

1
2
3
4
# Ensure modern TLS support (important on older Windows)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13

Import-Module -Name ([scriptblock]::Create((Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1' -UseBasicParsing -TimeoutSec 15).Content)) -Force -Global

Shortest / alias style (very common, but slightly less controlled):

1
irm https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1 | iex

Warning: irm … | iex executes the content directly — use the Import-Module + scriptblock version when clarity or scoping matters.

Reusable Helper Function Add this to your $PROFILE or a utility script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function Import-ModuleFromGitHub {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$RawUrl
    )

    try {
        $content = (Invoke-WebRequest -Uri $RawUrl -UseBasicParsing -TimeoutSec 15 -ErrorAction Stop).Content
        Import-Module -Name ([scriptblock]::Create($content)) -Force -Global
        Write-Verbose "Loaded module from $RawUrl" -Verbose
    }
    catch {
        Write-Error "Failed to load module from ${RawUrl}: $_"
    }
}

# Usage
Import-ModuleFromGitHub 'https://raw.githubusercontent.com/alekspish/modules/main/alekspower.psm1'

Security Considerations

Concern,Recommendation,Risk Level Arbitrary code execution,Only use repos you trust / control,High Private repo,Use PAT (classic) in Authorization header,— MITM / interception,“Always HTTPS (GitHub default), consider pinning”,Medium Persistence,Session-only — nothing saved to disk,Low (good) Older Windows TLS,Force TLS 1.2/1.3 explicitly,—

Private repo example with token:

1
2
3
$token = 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$headers = @{ Authorization = "token $token" }
$content = (Invoke-WebRequest -Uri $url -Headers $headers -UseBasicParsing).Content

Quick Verification After loading:

1
2
Get-Module MyTools               # See module info
Get-Command -Module MyTools      # List exported commands

When NOT to Use This Method Use the temp-folder download approach instead when:

You have a .psd1 manifest Multiple .ps1 files / subfolders You need proper module versioning / auto-discovery