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:
| |
When to Use This Method
- Your module is one single
.psm1file - 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 (
RemoteSignedorUnrestrictedare 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):
| |
Even more secure (with TLS + timeout):
| |
Shortest / alias style (very common, but slightly less controlled):
| |
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:
| |
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:
| |
Quick Verification After loading:
| |
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