如果我的文件中只有一个与文件同名的函数,这可能吗?我似乎记得以前读过它。像这样的东西:
你好.ps1
function hello {
Write-Host 'Hello, world'
}
最佳答案
我会完全摆脱函数调用。您根本不会丢失命名参数和 cmdlet 包装。所以这:
function Hello
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$Message
)
Write-Host "Hello, $Message!"
}
变成:
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$Message
)
Write-Host "Hello, $Message!"
你可以这样:
> .hello.ps1 "World"
关于powershell - 在没有点源的情况下在文件中调用 powershell 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11420554/