header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Customized display text for mandatory parameters
Last Post 06 Nov 2009 01: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 03: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 01: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 01: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 01: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 Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer