header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Customized display text for mandatory parameters
Last Post 06 Nov 2009 09:33 AM by ramz_g. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ramz_gUser is Offline
New Member
New Member
Posts:9
Avatar

--
26 Oct 2009 11:48 AM  
Hi,

I'm new to programming cmdlets. I was just trying out some cmdlet samples with mandatory parameters and I was just curious on how to do this : Can we actually define what text should appear on the screen when powershell prompts for the mandatory parameter?

If the question wasn't clear enough, here is a more detailed explanation :

Supppose i have a cmdlet named "Get-Files" which lists the files in a particular directory whose path is to be passed as a (mandatory) parameter to the cmdlet.

PS C:\Documents and Settings\ramz_g> Get-Files

cmdlet Get-Files at command pipeline position 1
Supply values for the following parameters:
Path:

In the above example, can I define the way in which the parameter is being displayed? ie., Can it be "Enter the path" instead of just "Path"?

Please suggest..


Thanks,
ramz_g
vishalramnaniUser is Offline
New Member
New Member
Posts:68
Avatar

--
30 Oct 2009 09:17 AM  
This is by design and not a good way to script. it better you supply the parameter with the command itself.

e.g.

Get-File -Path

To know the list of parameter and what it accepts you can say as below and will be given the syntax along with example and explanation.

Get-Help Get-file -detail

To full fill your requirement you can create a Script (PS1 file) with Read-Host Command let as below...

#########
#reading the input on host and saving it in variable.

$path = Read-host "Enter the Path"
Get-path -path $path
#########

and there you go. Just type this in Notepad and save it as name.ps1. execute it on powershell.

Hope this helps

Thanks.
Vishal Ramnani
MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config
vishalramnaniUser is Offline
New Member
New Member
Posts:68
Avatar

--
30 Oct 2009 09:21 AM  
You can also do it with this below one liner. (type of paste it directly on PS prompt instead of saving it as ps1 file)

Get-file -path $(Read-Host "Enter the path")

Thanks.
Vishal Ramnani
MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config
ramz_gUser is Offline
New Member
New Member
Posts:9
Avatar

--
06 Nov 2009 09:33 AM  
Hi Vishal,

Thanks a lot for your reply.. I apologize for the delay in replying to your post..
This helped : $(Read-Host "Enter the path")

Thanks a lot,
ramz_g
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer