Guest User

Untitled

a guest
Jan 8th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. # If there are existing Internet Explorer processes, close it
  2. $IE_Process = Get-Process iexplore -ErrorAction Ignore
  3. if ($IE_Process) {
  4. $IE_Close = Foreach-Object { $IE_Process.CloseMainWindow() }
  5. }
  6.  
  7. Stop-Process -Name "iexplore" -ErrorAction Ignore
  8.  
  9. # Login Information
  10. $url = "http://xxx.xxx.xxx.xxx/"
  11. $username = "xxxxxxxx"
  12. $password = "xxxxxxxx"
  13.  
  14. # Open an IE process
  15. $ie = New-Object -com internetexplorer.application;
  16. $ie.silent = $true
  17. $ie.navigate($url);
  18. while ($ie.Busy -eq $true)
  19. {
  20. Start-Sleep -s 1;
  21. }
  22.  
  23. # The stupid webpage needs to submit twice
  24. $ie.Document.getElementById("loginname").value = $username
  25. $ie.Document.getElementByID("password").value = $password
  26. $ie.Document.getElementById("button").Click()
  27. Start-Sleep -s 1;
  28. $ie.Document.getElementById("loginname").value = $username
  29. $ie.Document.getElementByID("password").value = $password
  30. $ie.Document.getElementById("button").Click()
  31.  
  32. # Close the IE process
  33. $IE_Process = Get-Process iexplore -ErrorAction Ignore
  34. if ($IE_Process) {
  35. $IE_Close = Foreach-Object { $IE_Process.CloseMainWindow() }
  36. }
  37.  
  38. Stop-Process -Name "iexplore" -ErrorAction Ignore
  39.  
  40. Remove-Variable -Name ie,username,password,url,IE_Process -ErrorAction Ignore
  41.  
  42. C:WINDOWSsystem32WindowsPowerShellv1.0powershell.exe -ExecutionPolicy RemoteSigned -File C:UsersMyNameDocumentsPowershelllogin_IE.ps1
  43.  
  44. C:WINDOWSsystem32WindowsPowerShellv1.0powershell.exe
  45.  
  46. -ExecutionPolicy Unrestricted -File C:UsersMyNameDocumentsPowershelllogin_IE.ps1
Add Comment
Please, Sign In to add comment