首页 > 系统相关 >powershell param : 无法将“param”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。

powershell param : 无法将“param”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。

时间:2024-01-30 19:14:00浏览次数:19  
标签:name age param Write address cmdlet powershell

前言全局说明

powershell param : 无法将“param”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。


一、源码


echo "脚本启动"

param($age, $address = "USA", $name)

Write-Host "Name: $name"
Write-Output "Address: $address"
Write-Output "Age: $age"


二、执行

.\test_param.ps1 -name "aaa" -age 11

报错信息:

param : 无法将“param”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 D:\stu-powershell\test_param_args\test_param.ps1:11 字符: 1

  • param($name, $address = "USA", $age)

三、解决方法

param($age, $address = "USA", $name) 前不能有其他代码执行

四、最终代码


param($age, $address = "USA", $name)

echo "脚本启动"

Write-Host "Name: $name"
Write-Output "Address: $address"
Write-Output "Age: $age"

image



免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。




参考、来源:
https://www.delftstack.com/zh/howto/powershell/pass-an-argument-to-a-powershell-script/



标签:name,age,param,Write,address,cmdlet,powershell
From: https://www.cnblogs.com/wutou/p/17997760

相关文章

  • Qt 解决qtcreator工程文件例程报错error: cannot initialize object parameter of typ
    qt下载好并且环境配置完成,kits和qt都已配置完成在qtcreator中,在终端手动编译qmakemake都完全没问题,但是在qtcreator中却报错。即使是新建工程例程都报错。版本qt5.6.0qtcreator4.11.0报错main.cpp:96:error:cannotinitializeobjectparameteroftype‘QWidget’wi......
  • Qt cannot initialize object parameter of type ‘QWidget‘ with an expression of
    报错如图:qtcreator工程文件例程报错error:cannotinitializeobjectparameteroftype‘QWidget’withanexpressionoftype‘tab_workface’问题分析可能因为qtcreator4.11.0basedonqt5.12版本略微冲突导致。。问题解决帮助->关于插件,将ClangCo......
  • Powershell 并发任务 | Runspace 线程 | 结果获取
    介绍在PowerShell中进行多任务处理(Multithreading或ParallelProcessing)主要目的是提高脚本的执行效率和性能。对于需要处理大量数据或执行多个独立任务的脚本来说尤其有用。提高性能:多任务处理允许脚本同时执行多个任务,从而加快整体执行速度。对于需要处理大型数据集或执......
  • Jenkins插件Extended Choice Parameter
    1.安装ExtendedChoiceParameter插件 2.参数化构建过程中添加ExtendedChoiceParameteMulti-LevelSingleSelect多级单选:用户从下拉列表中选择一个选项,然后出现另一个下拉列表,其中的选项取决于第一个值,在第二次选择时,可能会出现第三个下拉列表,具体取决于前两个选择,依此类推......
  • MySql执行Sql语句时出现“MySqlException: Parameter ‘@maxNo‘ must be defined.”
    1、......
  • 解决使用PowerShell执行命令出现“因为在此系统上禁止运行脚本”的问题
    1、......
  • (22)Powershell中的环境变量
    (22)Powershell中的环境变量本节介绍Powershell中环境变量的查看和使用,主要包括以下内容:为什么要设置环境变量。Powershell中环境变量的查看。Powershell中环境变量的更改。总结1.为什么要设置环境变量使用过Java语言的一定知道在安装完JDK之后要配置环......
  • (21)Powershell中的通配符
    (21)Powershell中的通配符1.使用通配符进行文件的模糊查找Powershell中的通配符可以实现模糊查找,也就是说可以对一组项(而不是单个项)进行查找。例如,如果想查找D:\MyPowerShell目录中所有扩展名为.ps1的文件,可以执行以下命令:PSC:\test>Get-ChildItemC:\test\*.ps1......
  • (20)Powershell中的特殊运算符
    (20)Powershell中的特殊运算符Powershell中除了常见的算术运算符,赋值运算符,比较运算符,位运算符,逻辑运算符,字符串的拆分和合并运算符,转义字符,还有一些特殊的运算符,这些特殊的运算符往往可以解决一些特殊的问题,比如执行运行命令,更改值的数据类型等。1.&(调用运算符)使用&(......
  • PowerShell编写Windows服务器的DDNS-ipv6客户端
    这个代码保存成ddnsv6.fm20.cn.ps1就能正常运行了functionGet-GUID(){#指定注册表路径$path="HKLM:\Software\Firadio\ddnsv6.fm20.cn"#如果注册表路径不存在则创建if(-not(Test-Path$path)){New-Item-Force-Path$path>$null}......