0

I have a powershell script where I want to be able to bring up a help screen. So far it accepts 3 parameters directoryURL loginprefix and validateOnly.

param(
    [Parameter(Mandatory=$true)]
    [string]$directoryUrl,

    #[Parameter(Mandatory=$true)]
    [string]$prependedPermissions,

    #[Parameter(Mandatory=$true)]
    [string]$validateOnly
);

What I want to check if someone types -help in the argument anywhere such as .\scriptName.ps1 -help it will be able to appear on the screen.

How can I do that?

magna_nz
  • 1,243
  • 5
  • 23
  • 42
  • possible duplicate of [Powershell Comment Based Help for Functions](http://stackoverflow.com/questions/4674587/powershell-comment-based-help-for-functions) – Eris Aug 18 '15 at 00:16

1 Answers1

1

This is propably not the way to go.

Powershell have very nice documentation features build in. If you add the following documentation comments in the top of your script, you will be able to just type help myscript.ps1 to get the help output.

<#
    .SYNOPSIS
    Short description of this scripts purpose
    .PARAMETER directoryUrl
    The URL to the directory
    .PARAMETER prependedPermissions
    Prepended permissions
    .PARAMETER validateOnly
    Only validate
#>
param(
    [Parameter(Mandatory=$true)]
    [string]$directoryUrl,

    #[Parameter(Mandatory=$true)]
    [string]$prependedPermissions,

    #[Parameter(Mandatory=$true)]
    [string]$validateOnly
);

You can find more information on the documentation feature in the following article https://technet.microsoft.com/en-us/magazine/hh500719.aspx

Jower
  • 565
  • 2
  • 8