header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Customized display text for mandatory parameters
Last Post 06 Nov 2009 12: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 02: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
    Vishal RamnaniUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    30 Oct 2009 12: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
    Vishal RamnaniUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    30 Oct 2009 12: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 12: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.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer