PowerShell for Admins

Working with PowershellGallery

Jonas Sommer Nielsen
4 min read
Share:

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.

Install-PSScriptAnalyzer.a

Installing the analyser is a breeze, suddenly I have two new commands. Lets try out the analyzer and see what it can do.

2015-09-10 (1)

Unfortunately the help on my machine is not updated, but the online version seems to be updated.

help Invoke-ScriptAnalyzer -online This goes to the online version. Also from the PowerShell Gallery PSScriptAnalyzer site there is a link to the Project Site at GitHub. 

ScriptAnalyzer-start-multithread

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

ScriptAnalyzer-start-multithread.ise.slim

The help from Write-Verbose tells me that they are referring to the -Message parameter.

help-write-verbose

That looks like a pretty easy fix. Going through the file and fixing the 6 warnings and suddenly there are none left.

ScriptAnalyzer-start-multithread.ise.fixed

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.

github.update

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.

update-version

Now I can update the module by running the command from the Publish Module page

PS> Publish-Module -Name -NuGetApiKey publish-module

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. 

Invoke-ScriptAnalyzer

“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.

Get-ScriptAnalyzerRule

Parameter Set: Default Get-ScriptAnalyzerRule [-CustomizedRulePath  ] [-Name  ] [-Severity  ] [ ]

Get-ScriptAnalyzerRule

The output gives us much useful information, severity level and a nice description of each rule.

More

PowerShellGallery.org has a nice GettingStarted page. 

ps.

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.

Contact me

Twitter @mrhvid
Web Jonas.SommerNielsen.dk

Related Articles

Sep 15, 2023

PowerShell Escape Room

PowerShell Escape Room by Michiel Hamers by Michiel Hamers https://about.me/michielhamers/ Why on earth you want to create an Escape Room with PowerShell as backend? I’ve always been a fan of escape rooms, so I decided to create my own for my kids. I wanted to make it something that would be challenging and fun for them, but also educational. I decided to use PowerShell as the backend for the escape room, as I’m a PowerShell developer and I thought it would be a great way to learn more about the language.

Sep 15, 2023

Microsoft Graph PowerShell Module: Getting Started Guide

Microsoft Graph PowerShell Module: Getting Started Guide by Jeff Brown Microsoft is retiring the Azure AD Graph API sometime after June 30, 2023 (announcement). This retirement includes the Azure AD PowerShell module. In its place, Microsoft has released the Microsoft Graph PowerShell module. The Microsoft Graph PowerShell module is the next-generation way of managing Microsoft cloud services using PowerShell. If you have used MSOnline or Azure AD PowerShell in the past, you’ll need to read on to learn about this new module.

Oct 8, 2021

ICYMI: PowerShell Week of 08-October-2021

Topics include VMWare, Windows 11, Web Reports and more… Special thanks to Robin Dadswell, Prasoon Karunan V, Kiran Patnayakuni and Kevin Laux How to gather your vCenter inventory data with this VMware PowerShell script by Scott Matteson on 7th October Inventory reports are a common request when administering a VMware vCenter environment. Learn how this VMware PowerShell script can make such requests quick and easy Building a Web Report in PowerShell, use the -Force Luke by Chris Noring on 8th October