include instructions in a script

Hello, so I'm trying to write a simple script for one of our users to restart a computer that's running a display in the lobby. The display sometimes freezes up and all we have to do is restart the compute and it loads the display on startup. So I got a simple script here:

param(
     [Parameter(Mandatory=$True)]
     [ValidateSet("localhost,Computer1,Computer2")]
     [String]
     $ComputerName
     )

Restart-Computer -ComputerName $ComputerName -Force -Verbose

It works just fine, but it looks like this when it's ran:

cmdlet Restart Computer.ps1 at command pipeline position 1 Supply values for the following parameters: ComputerName[0]:

I'd like to get rid of the top two lines and replace it with some instructions like:

"Type the NETBIOS name, IP address, or fully-qualified domain name of one or more computers in a comma-separated list.

I'm still pretty new to PowerShell, so I don't know if this is even possible.

Any help would be appreciated. Thanks!

July 31st, 2015 5:26pm

You can redesign your script to be interactive. Here is an example:

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 5:37pm

You can include a HelpMessage argument like so:

param(
     [Parameter(Mandatory=$True,HelpMessage='Type the NETBIOS name, IP address, or fully-qualified domain name of one of more computers in a comma-separated list.')]
     [ValidateSet("localhost,Computer1,Computer2")]
     [String]
     $ComputerName
     )

Try this out yourself and see if it'll suffice.

Edit: What this ends up doing is adding a line (see below) that will give the user an option to view a help message by entering !?.

cmdlet Restart Computer.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
ComputerName[0]: !?
Type the NETBIOS name, IP address, or fully-qualified domain name of one of more computers in a comma-separated list.
ComputerName[0]: 


July 31st, 2015 5:41pm

Both of those are the coolest things I've ever seen! They both work perfectly so I'll be using both examples and studying them for future use. 

Thanks a ton, guys!

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 5:47pm

You can include a HelpMessage argument like so:

param(
     [Parameter(Mandatory=$True,HelpMessage='Type the NETBIOS name, IP address, or fully-qualified domain name of one of more computers in a comma-separated list.')]
     [ValidateSet("localhost,Computer1,Computer2")]
     [String]
     $ComputerName
     )

Try this out yourself and see if it'll suffice.

Edit: What this ends up doing is adding a line (see below) that will give the user an option to view a help message by entering !?.

cmdlet Restart Computer.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
ComputerName[0]: !?
Type the NETBIOS name, IP address, or fully-qualified domain name of one of more computers in a comma-separated list.
ComputerName[0]: 


  • Edited by tommymaynard Friday, July 31, 2015 9:44 PM
  • Marked as answer by Alex.Franco Friday, July 31, 2015 9:45 PM
July 31st, 2015 9:39pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics