本文介绍了PowerShell参数-“术语'param'不被识别为cmdlet的名称"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑:
notepad # Starts Notepad
Get-Process notepad # Finds the processes named notepad
param(
[Parameter(Mandatory=$true)][string]$ProcessID
) #This should request user input, and store it in a variable#
Stop-Process $ProcessID # Stops the input process ID#
当我尝试运行此程序时,我遇到了:
When I try to run this, I'm met with:
param : The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:3 char:1
+ param(
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Stop-Process : Cannot bind parameter 'InputObject'. Cannot convert the "A" value of type "System.String" to type "System.Diagnostics.Process".
At line:6 char:14
+ Stop-Process $ProcessID
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Stop-Process], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.StopProcessCommand
我对PowerShell还是很陌生,由于这个原因,我感到非常困惑.要么是因为我听不懂,要么是因为它是清晨.
I'm quite new to PowerShell, and I'm severely confused because of this at the moment. Either because I don't understand it, or because it's early in the morning.
推荐答案
如果脚本需要参数,则Param
关键字必须是脚本中的第一条语句.
If your script requires arguments, the Param
keyword must be the first statement in the script.
但是,您可以稍后使用Read-Host
cmdlet要求用户输入:
However, you can ask the user for input later by using the Read-Host
cmdlet:
$processId = Read-Host "Enter the PID of the process to kill"
这篇关于PowerShell参数-“术语'param'不被识别为cmdlet的名称"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!