Advertisement
shalafi71

Untitled

Jul 19th, 2018
3,627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Clear the screen and stop all IE processes
  2. # You'll get errors if IE is running!
  3.  
  4. cls
  5. Get-Process iexplore | Stop-Process -Force
  6. Start-Sleep -s 1
  7.  
  8. # Variables be here
  9.  
  10. $username = "username";  # Your username
  11. $password = "password"; # Not the best way to input a password, but it works
  12. $loginUrl = "https://mail.company.com"; # Here be your login page
  13. $NewUser = "test" # Hopefully you've already captured this earlier in the script
  14.  
  15. # Second page you want to hit
  16. $AddURL = "https://mail.company.com/admin/user/create";
  17. # Add another string to hit a third page.  
  18. # $3rd-URL = "3rd-URL" or the like
  19. # Have not tried this.
  20.  
  21. # Initialize browser
  22. $ie = New-Object -com internetexplorer.application;
  23. $ie.visible = $true;
  24. $ie.navigate($loginUrl);
  25.  
  26. # If IE is still loading, wait until it's done.  We'll do this every time we call a page.
  27. while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }    #wait for browser idle
  28.  
  29. # Login, (Right-click -> Inspect Element on the button\field to get the quoted values)
  30. # Use "IHTMLDocument3_getElementsByName" or you will get errors when you go to subsequent pages!
  31.  
  32. ($ie.document.IHTMLDocument3_getElementsByName("username") |select -first 1).value = $username;
  33. ($ie.document.IHTMLDocument3_getElementsByName("password") |select -first 1).value = $password;
  34. ($ie.document.IHTMLDocument3_getElementsByName("Login") |select -first 1).click();
  35. while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }    #wait for browser idle
  36.  
  37. # Go to Create User page, input page 2 here, rinse and repeat to go deeper
  38. $ie.navigate($AddURL);
  39. while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }    #wait for browser idle
  40.  
  41. # Right-click -> Inspect Element all the fields\checkboxes you want to fill and select the appropriate name
  42. ($ie.document.IHTMLDocument3_getElementsByName("user") |select -first 1).value = $NewUser;
  43. ($ie.document.IHTMLDocument3_getElementsByName("name") |select -first 1).value = "Test Test";
  44. # Here's a tick-box. Keep it in order, down the page, top to bottom, less confusing
  45. ($ie.document.IHTMLDocument3_getElementsByName("email_service") |select -first 1).click();
  46. ($ie.document.IHTMLDocument3_getElementsByName("groupware_service") |select -first 1).click();
  47. ($ie.document.IHTMLDocument3_getElementsByName("password") |select -first 1).value = "$password";
  48. ($ie.document.IHTMLDocument3_getElementsByName("confirm") |select -first 1).value = "$password";
  49. ($ie.document.IHTMLDocument3_getElementsByName("Create User") |select -first 1).click();
  50. while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }    #wait for browser idle
  51.  
  52. # Stop IE again, we're done here
  53. # Make it all invisible, forgot that part
  54. Get-Process iexplore | Stop-Process -Force
  55. Start-Sleep -s 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement