Question Interface graphique

Plus d'informations
il y a 8 ans 4 mois #24502 par Cedric
Interface graphique a été créé par Cedric
Bonjour,

Je suis entrain de développer une interface graphique pour récupérer le mot de passe d'un ordinateur dans l'AD.
Je lance mon powershell en ISE, il me demande bien mes identifiants (avec le get-credential). Ensuite mon interface graphique s'ouvre et lorsque je clique sur recherche rien ne se passe. J'arrête l’exécution de mon script.
Je le relance il me demande à nouveau de m'authentifier (normal), je renseigne le nom de la machine et la il m'affiche bien le mot de passe.
J'ai l'impression que c'est un problème de porté de variable.
Si vous avez une idée, je suis preneur. Merci
[code:1]
Import-Module ActiveDirectory


Add-Type -AssemblyName System.Windows.Forms

$adm = get-credential -Message \"Merci de renseigner votre compte admin\"

$Form = New-Object system.Windows.Forms.Form
$Form.Text = \"Gestion des mots de passes\"
$Form.TopMost = $true
$Form.Width = 400
$Form.Height = 400

$label_nom = New-Object system.windows.Forms.Label
$label_nom.Text = \"Nom de machine :\"
$label_nom.AutoSize = $true
$label_nom.Width = 25
$label_nom.Height = 10
$label_nom.location = new-object system.drawing.point(10,140)
$label_nom.Font = \"Microsoft Sans Serif,10\"
$Form.controls.Add($label_nom)

$textBox_nom = New-Object system.windows.Forms.TextBox
$textBox_nom.Width = 100
$textBox_nom.Height = 20
$textBox_nom.location = new-object system.drawing.point(200,135)
$textBox_nom.Font = \"Microsoft Sans Serif,10\"
$Form.controls.Add($textBox_nom)

$label_mdp = New-Object system.windows.Forms.Label
$label_mdp.Text = \"Mot de passe de la machine :\"
$label_mdp.AutoSize = $true
$label_mdp.Width = 25
$label_mdp.Height = 10
$label_mdp.location = new-object system.drawing.point(10,180)
$label_mdp.Font = \"Microsoft Sans Serif,10\"
$Form.controls.Add($label_mdp)

$textBox_mdp = New-Object system.windows.Forms.TextBox
$textBox_mdp.Width = 100
$textBox_mdp.Height = 20
$textBox_mdp.location = new-object system.drawing.point(200,175)
$textBox_mdp.Font = \"Microsoft Sans Serif,10\"
$Form.controls.Add($textBox_mdp)

$button_search = New-Object system.windows.Forms.Button
$button_search.Text = \"Recherche\"
$button_search.Width = 90
$button_search.Height = 30
$button_search.location = new-object system.drawing.point(60,220)
$button_search.Font = \"Microsoft Sans Serif,10\"
$button_search.Add_Click($button_search_OnClick)
$Form.controls.Add($button_search)



$button_search_OnClick=
{

$machine=$textBox_nom.Text

$mdp=Get-ADComputer $machine -Properties * -Credential $adm
if ($mdp.'ms-Mcs-AdmPwd' -eq $null)
{
$aff_mdp=\"Inconnu\"
$textBox_mdP.Text = $aff_mdp
}
else
{
$aff_mdp=$mdp.'ms-Mcs-AdmPwd'
$textBox_mdP.Text = $aff_mdp
}

}

[void]$Form.ShowDialog()
[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 4 mois #24503 par Cedric
Réponse de Cedric sur le sujet Re:Interface graphique
J'ai trouvé mon erreur.
J'appelle ma fonction avant de la déclarer. :whistle:
Cela fonctionne maintenant.

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.037 secondes
Propulsé par Kunena