Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Clear the screen and stop all IE processes
- # You'll get errors if IE is running!
- cls
- Get-Process iexplore | Stop-Process -Force
- Start-Sleep -s 1
- # Variables be here
- $username = "username"; # Your username
- $password = "password"; # Not the best way to input a password, but it works
- $loginUrl = "https://mail.company.com"; # Here be your login page
- $NewUser = "test" # Hopefully you've already captured this earlier in the script
- # Second page you want to hit
- $AddURL = "https://mail.company.com/admin/user/create";
- # Add another string to hit a third page.
- # $3rd-URL = "3rd-URL" or the like
- # Have not tried this.
- # Initialize browser
- $ie = New-Object -com internetexplorer.application;
- $ie.visible = $true;
- $ie.navigate($loginUrl);
- # If IE is still loading, wait until it's done. We'll do this every time we call a page.
- while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle
- # Login, (Right-click -> Inspect Element on the button\field to get the quoted values)
- # Use "IHTMLDocument3_getElementsByName" or you will get errors when you go to subsequent pages!
- ($ie.document.IHTMLDocument3_getElementsByName("username") |select -first 1).value = $username;
- ($ie.document.IHTMLDocument3_getElementsByName("password") |select -first 1).value = $password;
- ($ie.document.IHTMLDocument3_getElementsByName("Login") |select -first 1).click();
- while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle
- # Go to Create User page, input page 2 here, rinse and repeat to go deeper
- $ie.navigate($AddURL);
- while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle
- # Right-click -> Inspect Element all the fields\checkboxes you want to fill and select the appropriate name
- ($ie.document.IHTMLDocument3_getElementsByName("user") |select -first 1).value = $NewUser;
- ($ie.document.IHTMLDocument3_getElementsByName("name") |select -first 1).value = "Test Test";
- # Here's a tick-box. Keep it in order, down the page, top to bottom, less confusing
- ($ie.document.IHTMLDocument3_getElementsByName("email_service") |select -first 1).click();
- ($ie.document.IHTMLDocument3_getElementsByName("groupware_service") |select -first 1).click();
- ($ie.document.IHTMLDocument3_getElementsByName("password") |select -first 1).value = "$password";
- ($ie.document.IHTMLDocument3_getElementsByName("confirm") |select -first 1).value = "$password";
- ($ie.document.IHTMLDocument3_getElementsByName("Create User") |select -first 1).click();
- while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle
- # Stop IE again, we're done here
- # Make it all invisible, forgot that part
- Get-Process iexplore | Stop-Process -Force
- Start-Sleep -s 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement