且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在没有点源的情况下在文件中调用 powershell 函数

更新时间:2023-10-27 21:41:34

我会完全摆脱函数调用.您根本不会丢失命名参数和 cmdlet 包装.所以这个:

I would get rid of the function call altogether. You don't lose named parameters and cmdlet wrapping at all. So this:

 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"