After my two first posts (Multithreading using jobs, List users logged on to your machines) where I mentioned PowershellGallery.com a few times and after Warren talked about the Gallery a few days ago I felt like digging a little deeper to see if I was actually doing it right.
So I wrote them an email and this was their reply:
“Hi Jonas – The “limited preview” designation on the PowerShell Gallery is because we are doing significant development to the site. However, there is nothing about that status which should prevent you from sharing your code.
A couple of things you will want to consider as you get ready to publish to the Gallery:
- You will want to scan your modules with PSSCriptAnalyzer (see http://www.powershellgallery.com/packages/PSScriptAnalyzer/), as we scan all modules that have been posted with that tool. Anything flagged as an “error” must be corrected, things flagged as “warnings” should be fixed.
- Most submitters have a project site on GitHub, or something of that nature, that they link to from the Gallery. That allows them to get feedback on what they have submitted, & it’s something we would recommend.
Hope this helps – The PowerShell Gallery Operations Team”
Really nice feedback. To the commandline.
Installing the analyser is a breeze, suddenly I have two new commands. Lets try out the analyzer and see what it can do.
Unfortunately the help on my machine is not updated, but the online version seems to be updated.
help Invoke-ScriptAnalyzer -online
This is kind of neat and it looks like I only have one warning, though 6 times.
“Cmdlet ‘Write-Verbose’ has positional parameter. Please use named parameters instead of positional parameters when calling a command.”
Opening the same file in ISE looking at line 92 and running the script analyser
The help from Write-Verbose tells me that they are referring to the -Message parameter.
That looks like a pretty easy fix. Going through the file and fixing the 6 warnings and suddenly there are none left.
I’m sure the fact that there weren’t more errors was mostly due to dumb luck combined with me testing ISESteroids at the time of writing. (Side note: Try it out. Install-Module ISESteroids. It is really AWSOME or quoting Tim Cook; It’s AMAZING) ISESteroids is an add-on for ISE which adds some neat stuff like highlighting errors in the code but that’s a subject for some other day. Let’s just say it saved my behind this time.
Now that really wasn’t too bad. To update the code on PowerShellGallery I need to increment the version of the module. This is done in the manifest file .psd1.
Now I can update the module by running the command from the Publish Module page
PS> Publish-Module -Name -NuGetApiKey
Now the code is accessible to all …. And there was much rejoicing.
Looking a little closer at the ScriptAnalyzer
Lets see what the help says.
“Parameter Set: Default Invoke-ScriptAnalyzer [-Path] [-CustomizedRulePath ] [-ExcludeRule ] [-IncludeRule ] [-LoggerPath ] [-Recurse] [-Severity ] [ ]
Detailed Description Invoke-ScriptAnalyzer starts analyzing one or more specified scripts by using ScriptAnalyzer, evaluating your scripts against a set of best practice measures called rules. ScriptAnalyzer works by evaluating scripts against either all available rules, or against a set of rules that you specify by adding the ExcludeRule or IncludeRule parameters. After ScriptAnalyzer finishes evaluating your scripts, it displays results in the console window.”
Looks like IncludeRule and ExcludeRule parameters are straight forward. To get a list of rules and their descriptions Get-ScriptAnalyzerRule is very helpful.
Parameter Set: Default Get-ScriptAnalyzerRule [-CustomizedRulePath ] [-Name ] [-Severity ] [ ]
The output gives us much useful information, severity level and a nice description of each rule.
PowerShellGallery.org has a nice GettingStarted page.
Remember PowerShell Summit Europe starts Monday. Check out the Event Schedule and I hope to see you there. If on the other hand you’re missing out check out these videos from PowerShell Summit North America 2015.