【发布时间】:2015-12-09 20:34:39
【问题描述】:
我有两个 powershell 脚本,一个具有检查作为参数传递的变量“name”的值的函数。如果不匹配“John”,则结果为 2,否则,结果为 0(包含在函数中)。
这里是函数脚本:
Function test {
Param (
$name = $(throw "need -name"),
$result = 0
)
Process {
if($name -ne "John") {
Write-Host "Name is incorrect"
$result = 2
} else {
Write-Host "Student is correct"
}
}
}
第二个脚本调用这个函数并运行为 -
Import-Module C:\function.ps1
test -name Sandra
现在我想将结果(或状态)从函数返回到第二个脚本,并根据结果在第二个脚本中添加更多条件。为了实现这一点,脚本或函数需要进行哪些更改?
【问题讨论】:
标签: powershell