另一个 PowerShell 函数返回值和 Write-Output 可以被理解为:一个 PowerShell 函数同时返回值和输出内容。 代码示例:
function ExampleFunction{ [Cmdletbinding()] Param( [Parameter(Mandatory=$true)] [String]$InputString ) Write-Output "输入的字符串是: $InputString" return "这是返回的字符串" }
$Result = ExampleFunction -InputString "Hello World" Write-Output $Result
#输出: #输入的字符串是: Hello World #这是返回的字符串