【发布时间】:2021-11-21 03:48:09
【问题描述】:
这是一个后续
Writing a cmdlet in PowerShell
我得到了这个关于如何将函数声明为 cmdlet 的链接:
使用另一个页面
我试过了
function Send-Greeting
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string] $Name
)
Process
{
Write-Host ("Hello " + $Name + "!")
}
}
我运行了这个脚本,但它没有按预期工作:
PS > .\Send-Greeting.ps1
PS > Send-Greeting Joe Send-Greeting : The term 'Send-Greeting' 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:1 char:1
+ Send-Greeting Joe
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Send-Greeting:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
如何将我的新 cmdlet 导出到 PowerShell 环境中,以便将其用作内置 cmdlet?
【问题讨论】:
-
将
.\Send-Greeting.ps1更改为. .\Send-Greeting.ps1- 点源将确保函数定义在调用者范围内持续存在
标签: powershell cmdlets cmdlet