none
Parameter Types in Funcitons RRS feed

  • Question

  • hi guys, 

    can anyone help me explain 

    how to create below mentioned types of parameters, and what other types do exists

    how to create a select from list parameter like the (ForegroundColor) 

    Write-Host "hello world" -ForegroundColor Yellow

    how to create a parameter that activates or its value becomes true once it is written like (-force, or -verbose)

    Remove-Item $item -force
    thanks in advance, 

    Monday, January 25, 2016 7:13 AM

Answers

  • Hi Vagharsh,

    A1. It can be done using something called  'ValidateSet'

    Read more on about_Functions_Advanced_Parameters

    A2.  Its called a Switch Parameter :(Read more from the link above)

     Switch parameters are parameters with no parameter value. They are effective only when they are used and have only one effect.

    Basically if you use them the $force value becomes $true and you can have a if($force){"do this extra step"}

    to make it run only when its mentioned.

    Using Switch Parameters


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Marked as answer by Vagho Monday, January 25, 2016 10:34 AM
    Monday, January 25, 2016 8:54 AM