So I've been publishing my script to the PowerShell Gallery, using their required comment header with version, GUID, author, etc. The problem is, I've noticed that this comment header addition has broken Get-Help, which used to parse the comment based help header in my script, generating formatted help output to the console. I've submitted feedback about allowing the PSScriptInfo header to come AFTER the other comment header, to the PS Gallery team, but I'm seeking a workaround in the meantime.
I'm looking for a hopefully one-line solution, where maybe I could skip over or drop/parse out the PSScriptInfo header, and then feed the rest to Get-Help? Going to try this approach and report back if no one beats me to it. I'm thinking a simple temp file. I searched stackoverflow and didn't see anyone else asking this question, so I wanted to make this problem/solution searchable by others.
This is what I'm actually seeing (with PSScriptInfo header):
PS> Get-Help .\New-SubredditHTMLArchive.ps1 -Full
New-SubredditHTMLArchive.ps1 [[-Subreddit] <string>] [[-Subreddits] <string[]>] [-InstallPackages] [-Background]
This is what I'm expecting to see (without PSScriptInfo header):
PS> Get-Help .\New-SubredditHTMLArchive.ps1 -Full
NAME
C:\github\New-SubredditHTMLArchive\New-SubredditHTMLArchive.ps1
SYNOPSIS
Checks for (or installs) prerequisites, then uses BDFR and BDFR-HTML Python modules to generate a subreddit HTML archive.
By default, creates root 'New-SubredditHTMLArchive' output folder and under your %USERPROFILE% ($env:USERPROFILE) Documents folder.
Runs itself as a scheduled task as the current user, as an interactive console by default. The task can be run as a background task with the -Background parameter, allowing use of the lock screen.
SYNTAX
C:\github\New-SubredditHTMLArchive\New-SubredditHTMLArchive.ps1 [[-Subreddit] <String>] [[-Subreddits] <String[]>] [-InstallPackages] [-Background] [<CommonParameters>]
DESCRIPTION
If you already have Python 3.9+, Git 2+, and GitHub CLI 2+ installed, you can skip this section.
This script does NOT require administrator privileges to run, or to install the Python modules, WITHOUT the -InstallPackages parameter.
On first run, you must include the -InstallPackages parameter, or manually install the below software packages before running this script.
When installing these packages automatically, the user must confirm a UAC admin prompt for each package, allowing the installer to make changes to their computer.
1. Git: ... (only when manually installing)
2. GitHub CLI: ... (only when manually installing)
i. You'll need to launch cmd.exe and authenticate with 'gh auth login', and follow the prompts, pasting the OTP into your browser, after logging into your GitHub account (or make a new account).
3. Python 3.9+ (includes pip): ... (only when manually installing)
i. At beginning of install, YOU MUST CHECK 'Add Python 3.x to PATH'. (So PowerShell can call python.exe and pip.exe from anywhere)
This script uses the following Python modules, which are detected and installed automatically via pip:
1. BDFR: ...
2. BDFR-HTML: ...
i. When running setup.py to install BDFR-HTML (via script or manually), you may get an install error from Pillow about zlib being missing. You may need to run 'pip install pillow' from an elevated command prompt, so that Pillow
installs correctly.
ii. For manual BDFR-HTML install in case of Pillow install error: From an elevated CMD window, type these two quoted commands: 1) "cd %USERPROFILE%\Documents\BDFR\module_clone\bdfr-html", 2) "python.exe setup.py install"
iii. ...
PARAMETERS
-Subreddit <String>
The name of the subreddit (as it appears after the /r/ in the URL) that will be archived.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Subreddits <String[]>
An array of subreddit names (as they appear after the /r/ in the URL) that will be archived.
Also generates a master index.html containing links to all of the other generated subreddit index.html files.
All generated subreddit folders, files, and index pages, are automatically packaged into a ZIP file.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-InstallPackages [<SwitchParameter>]
The script will attempt to install ONLY MISSING pre-requisite packages: Python 3, GitHub, and Git
When 'python.exe', 'gh.exe', or 'git.exe' are already in your $env:path, and executable from PowerShell, they will NOT be installed or modified.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Background [<SwitchParameter>]
The script will spawn the scheduled task with S4U logon type instead of Interactive logon type. Requires approval of an admin UAC prompt to spawn the task.
This switch allows the script to keep running in the background, regardless of user's logon state (such as lock screens, when running overnight).
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Last update: Friday, March 18, 2022 6:44:49 PM
-------------------------- EXAMPLE 1 --------------------------
PS>.\New-SubredditHTMLArchive.ps1 -Subreddit PowerShell -InstallPackages
-------------------------- EXAMPLE 2 --------------------------
PS>.\New-SubredditHTMLArchive.ps1 -Subreddit PowerShell
-------------------------- EXAMPLE 3 --------------------------
PS>.\New-SubredditHTMLArchive.ps1 -Subreddits (Get-Content "$($env:USERPROFILE)\Desktop\subreddit_list.txt") -InstallPackages
-------------------------- EXAMPLE 4 --------------------------
PS>.\New-SubredditHTMLArchive.ps1 -Subreddits 'PowerShell','Python','AmateurRadio','HackRF','GNURadio','OpenV2K','DataHoarder','AtheistHavens','Onions' -Background