简体   繁体   中英

How to pass Powershell argument with -silent

Here is my ps script:-

param (
    [Parameter(ParameterSetName='runParam', Position=1, Mandatory=$false)]
    [String]$runParam
)

Write-Host $runParam

I would like to pass an argument with -silent . It doesn't allow me to pass any argument with -

Is there any way to pass an argument with - ?

I can execute and pass any argument without - . It works fine. But I have to pass it as -silent

I get error as:-

run.ps1 : A parameter cannot be found that matches parameter name 'silent'. At line:1 char:11 + .\\run.ps1 -silent + ~~~~~~~ + CategoryInfo : InvalidArgument: (:) [run.ps1], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,run.ps1

Read Get-Help 'about_parameters'

Most Windows PowerShell commands, such as cmdlets, functions, and scripts, rely on parameters to allow users to select options or provide input. The parameters follow the command name and have the following form:

  -<parameter_name> <parameter_value> 

The name of the parameter is preceded by a hyphen ( - ), which signals to Windows PowerShell that the word following the hyphen is a parameter name.

Choose any of the following methods to pass a leading hyphen as a string

PS D:\PShell> .\run.ps1 -runParam -silent ### declared parameter type is string
-silent
PS D:\PShell> .\run.ps1 `-silent          ### escape: a backtick character
-silent
PS D:\PShell> .\run.ps1 '-silent'         ### escape: single quotes
-silent
PS D:\PShell> .\run.ps1 "-silent"         ### escape: double quotes
-silent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM