我使用 PS Remoting,Powershell 2.0。
我需要调用返回布尔值($true 或 $false)的函数。
我的功能:
Function TryDisableClientForCredSSP()
{
try
{
WriteTrace "[TryDisableClientForCredSSP]. Disable-WSManCredSSP -Role Client "
$script=Convert-StringToScriptBlock("Disable-WSManCredSSP -Role Client ")
Caller($script)
WriteTrace "[TryDisableClientForCredSSP]. winrm get winrm/config/client/auth [($env:COMPUTERNAME)]"
$script=Convert-StringToScriptBlock("winrm get winrm/config/client/auth")
Caller($script);
return $true;
}
catch
{
Write-Verbose "[TryDisableClientForCredSSP] Error "
Write-Verbose $_
Write-Host $_.Exception.Message`r`n
return $false;
}
}
注意:WriteTrace 函数只做 Write-Host。
我用这个:
$ok = TryDisableClientForCredSSP;
WriteTrace "[TryDisableClientForCredSSP]. $ok"
if ($ok -eq $true)
{
WriteTrace "[TryDisableClientForCredSSP]. OK true"
}
else
{
WriteTrace "[TryDisableClientForCredSSP]. KO false"
}
我得到这个输出:
[TryDisableClientForCredSSP]. Auth Basic = true Digest = true Kerberos = true Negotiate = true Certificate = true CredSSP = false True
[TryDisableClientForCredSSP]. OK true
我希望这一行输出“[TryDisableClientForCredSSP].True”
WriteTrace "[TryDisableClientForCredSSP]. $ok"
有什么建议么 ?