我正在尝试创建一个Powershell GUI函数,通过一个颜色条显示连接/未连接状态,通过TextBox输入插入计算机名。
我正在使用Test函数来实现输出。
我有点搞不懂我的else/if语句。
如果没有插入计算机,它应该弹出一个窗口,如果没有测试-WSMan是可能的,它会抛出一个红色的错误,如果连接它应该有一个绿灯。
即使有一台不知名的电脑,我也会开绿灯,我的代码也不会停止运行。
这是我的密码
function checkinfo {
$Server=$textboxComputername.text;
if (-not $textboxComputername.Text)
{
[System.Windows.Forms.MessageBox]::Show('No computer
specified', 'Error')
Throw 'No Computer specified'
}
elseif
(Test-WSMan $Server ) {
$label_PingStatus.Text = "OK";
$label_PingStatus.ForeColor = "green"
Write-Status -Message "Connected to $Server"
$picturebox1.BackColor = "Green"
else
If (-not (Test-WSMan $Server))
{
$picturebox1.BackColor = "Red"
Write-Status -Message "Not Connected to $Server"
[System.Windows.Forms.MessageBox]::Show('No such computer or computer is offline', 'Error')
Throw 'No such computer or computer is offline'
}谢谢你的指导
发布于 2020-05-07 15:43:33
您指定的代码甚至没有运行
从这里开始:
Function checkinfo {
$Server=$textboxComputername.text;
If (-not $Computername) {
[System.Windows.Forms.MessageBox]::Show('No computer specified', 'Error')
Throw 'No Computer specified'
}
Else {
If (Test-WSMan $Server ) {
Write-Host "Connected to $Server"
}
Else {
Write-Host "Not Connected to $Server"
[System.Windows.Forms.MessageBox]::Show('Not connected', 'Error')
Throw 'Test-WsMan failed'
}
}
}https://stackoverflow.com/questions/61661670
复制相似问题