Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell #requires and .SYNOPSIS don't play nice

You can tag your PowerShell script as requiring a particular version:

#requires -version 2.0

You can put extra help text in your PowerShell script:

<#
.SYNOPSIS

Frobnicates the blargnozzle.
#>

Unfortunately, they don't appear to play nice:

  • If you put the #requires on line 1, Get-Help Frob-Blargnozzle.ps1 doesn't display the synopsis, only the parameter summary.
  • If you put the #requires on any line other than line one, even if immediately after the <# ... #> comment, it is ignored.

Suggestions?

like image 522
Roger Lipscombe Avatar asked Nov 19 '12 19:11

Roger Lipscombe


People also ask

What is the PowerShell used for?

As a scripting language, PowerShell is commonly used for automating the management of systems. It is also used to build, test, and deploy solutions, often in CI/CD environments. PowerShell is built on the . NET Common Language Runtime (CLR).

Is PowerShell same as CMD?

PowerShell is a more advanced version of cmd. It is not only an interface but also a scripting language that is used to carry out administrative tasks more easily. Most of the commands executed on cmd can be run on PowerShell as well.

Is PowerShell still used?

It is the tool to go to, for folks doing DevOps automation tasks in Microsoft technologies. Modern Windows server versions are also mostly controlled via PowerShell cmdlets, the classical GUIs are now being made to act as frontend to those scripts, like the new Web based admin console.

Is PowerShell Linux or Windows?

Windows PowerShell is exclusive to Windows -- where it is included by default -- and is built on the . NET Framework. This tutorial uses the latest version of PowerShell -- 7.2. 4 at the time of writing -- on both Windows and Linux.


1 Answers

Try to put #requires -version 2.0 one line up the closing comment #>

<#
.SYNOPSIS

Frobnicates the blargnozzle.

#requires -version 2.0
#>
like image 73
CB. Avatar answered Sep 19 '22 11:09

CB.