I'm trying to create a Powershell GUI function to show a Connected/Not connected status via a color bar, computername inserted via a TextBox input.
I'm using Test-WSMan function to have my output.
I'm a bit confused with my else/if statement.
It should pop-up a window if no computer inserted, if no test-WSMan is possible it throw a red error if connects it should have a green lights.
Even with an unknown computer i allways have green light and my code don't stop running.
Here's my code
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'
}
Thanks for your guidance
Aucun commentaire:
Enregistrer un commentaire