Set-PowerShellScriptSig 1.1 Published

A fairly significant update, 1.1’s Mac component leverages AppleScript’s Choose File so you can select multiple PowerShell files to sign at once. It took a bit longer than I thought it would because while you can create generic list objects in PowerShell functions, what gets returned is a generic array. Sigh.

Anyway, it’s up at https://www.powershellgallery.com/packages/Set-PowerShellScriptSig/1.1, and works on both Windows and macOS.

Get-MacInfo update

Not a huge one, added iBridge data, so it now shows SIP/SSV/secure boot status, few other things. There’s not much to it if you’re running on Intel, most of this is AppleSilicon only. Available from the PowerShell Gallery at https://www.powershellgallery.com/packages/Get-MacInfo and the github site https://github.com/johncwelch/Get-MacInfo has been updated as well.

Publishing PowerShell Modules to PowerShell Gallery

I have the BEST post titles, right?

Now that I have Get-MacInfo working correctly on both Intel and Apple Silicon Macs, it was time to post it to the PowerShell Gallery so that it can be installed the correct way for PowerShell modules. Like everything, there’s a process, but it’s not an awful one. Note that this builds on my previous post about creating my first PowerShell module.

Account Creation

The first step here is to create an account on the PowerShell Gallery and get an access token. Both are pretty straightforward, especially if you have an MS365 account you can use for this already. The only weirdness is the PS Gallery uses Gravatar for your profile picture, which is like…Gravatar still exists? It does, and PS Gallery uses it for your profile pic!

Preflight

Before submitting, you want to make sure you have the module folder with at least the psm1 and psd1 files in it and ready to go.

ScriptAnalyzer

The next step is to run the psm1 file through the PowerShell Static Analyzer, PSScriptAnalyzer. To install: Install-Module -Name PSScriptAnalyzer, then to run: Invoke-ScriptAnalyzer <path to psm1 file>.

Most of what I get is fussing about using Invoke-Expression (necessary in my case), using Write-Host, (you can usually replace with Write-Output), and trailing whitespace at the end of a line. Fix the stuff that makes sense to fix.

Test-ModuleManifest

Next, you’ll want to test the manifest, the psd1 file with Test-ModuleManifest <path to psd1 file>, and fix any errors in that. The manifest is important to the PS Gallery. Some PS Gallery-specific things:

  • ModuleVersion: this has to be different every time you upload the module
  • Description: Be clear, but concise
  • Tags: important since people search by those. DO NOT PUT SPACES IN YOUR TAGS EVEN IF QUOTED, PS GALLERY WILL NOT UPLOAD IF YOU DO. Many error messages happen if you try to have tags with spaces.
  • LicenseURI: URL for your project’s license
  • ProjectURI: URL for the project itself
  • ReleaseNotes: The main points work
  • HelpInfoURI: optional but can be useful
Test-ScriptFileInfo

If you have any standalone ps1 files in your module, use Test-ScriptFileInfo on those.

.NET

Install .NET for macOS. You have to have this to publish to PS Gallery. You also have to have the path to the dotnet command in your path. The installer for the Current version of .Net is available at https://dotnet.microsoft.com/en-us/download/dotnet, install it, and then add it to your path, most likely in ~/.zprofile. The path I used for it was /Users/<username/.dotnet but any path to the correct dotnet command will work.

Publishing the Module

Now we’re ready to publish! The command to do so is pretty simple, it’s: Publish-Module -Path <path to module folder> -NuGetApiKey <pat you get from PS Gallery>

Assuming no massive problems in your script, it shouldn’t take too long, et voila, you have a module in the gallery!

That’s really all there is to it. If you update the module, make sure to change the version number and the release notes in the manifest and re-run Publish-Module.