Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. {
  2. PowerShell objPowershell = PowerShell.Create();
  3.  
  4. objPowershell.Commands.Clear();
  5. objPowershell.Commands.AddScript(" test-connection -count 1 " + TxtIp.Text);
  6.  
  7.  
  8.  
  9. //On ajoute la première ligne de script
  10.  
  11.  
  12. Collection<PSObject> colResults = objPowershell.Invoke();
  13. if (colResults.Count>=1)
  14. {
  15. testdeconnec.Text = "Réussi";
  16. }
  17. //On exécute les 3 lignes de script qui ajoute un utilisateur dans AD
  18. objPowershell.Commands.Clear();
  19. objPowershell.Commands.AddScript("$Error");
  20. Collection<PSObject> colmarchepas = objPowershell.Invoke();
  21. if (colmarchepas.Count>0)
  22. {
  23. testdeconnec.Text = "Échouer";
  24. }
  25.  
  26.  
  27. //ON LIBÈRE LA MÉMOIRE POUR L'OBJET POWERSHELL
  28. objPowershell.Dispose();
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement