0

I know this was working last night when I wrote it. We went through a domain cutover today, and it now it is returning null-valued expressions at Powershell.exe -windowstyle hidden.

I removed it and received errors at each of the getelementby. The intent is for it to prompt users for a user name and password and pass it to two sites in sequence. I double checked my element ids.

PowerShell.exe -windowstyle hidden {
    $url = "https://www.e-access.att.com/webet/DeltekTC/welcome.msv"
    $x=""
    $y=""

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "Deltek Logon Assistant"
    $objForm.Size = New-Object System.Drawing.Size(300,175)
    $objForm.StartPosition = "CenterScreen"

    $objForm.KeyPreview = $True
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {$x=$objTextBox1.Text;$y=$objTextbox2.Text;$objForm.Close()}})
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,105)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.Add_Click({$x=$objTextBox1.Text;$y=$objTextbox2.Text;$objForm.Close()})
    $objForm.Controls.Add($OKButton)

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(150,105)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.Add_Click({$objForm.Close()})
    $objForm.Controls.Add($CancelButton)

    #- User
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,10)
    $objLabel.Size = New-Object System.Drawing.Size(280,20)
    $objLabel.Text = "Username:"
    $objForm.Controls.Add($objLabel)

    $objTextBox1 = New-Object System.Windows.Forms.MaskedTextBox
    $objTextBox1.Location = New-Object System.Drawing.Size(10,30)
    $objTextBox1.Size = New-Object System.Drawing.Size(260,20)
    $objForm.Controls.Add($objTextBox1)


    #-Pass
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,55)
    $objLabel.Size = New-Object System.Drawing.Size(280,20)
    $objLabel.Text = "Password:"
    $objForm.Controls.Add($objLabel)

    $objTextBox2 = New-Object System.Windows.Forms.MaskedTextBox
    $objTextBox2.Location = New-Object System.Drawing.Size(10,75)
    $objTextBox2.Size = New-Object System.Drawing.Size(260,20)
    #- this is what makes your password show up as **
    $objTextBox2.PasswordChar = '*'
    $objForm.Controls.Add($objTextBox2)

    $objForm.Topmost = $True

    $objForm.Add_Shown({$objForm.Activate()})
    [void] $objForm.ShowDialog()

    $x
    $y


    $ie = New-Object -com internetexplorer.application;
    $ie.visible = $true;
    $ie.navigate($url);

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("userid").value = $x
    $ie.Document.getElementByID("password").value= $y
    $ie.Document.getElementById("btnSubmit").Click();

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("successOK").Click();

    while ($ie.Busy -eq $true)
    {
        Start-Sleep -Milliseconds 1000;
    }

    $ie.Document.getElementById("uid").value = $x
    $ie.Document.getElementByID("passField").value= $y
    $ie.Document.getElementById("loginButton").Click();
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Powerboy2
  • 69
  • 5
  • Which part is not working for you? I was able to run this fine, but obviously can't test after the first log in section. Also, you do not need the semicolons after .Click() – Michael Burns Feb 27 '14 at 23:16
  • I get past my function and into IE however i believe this may end up being host settings that are preventing this from working. The IE is running in a protected zone. – Powerboy2 Mar 18 '14 at 00:14
  • This ended up being a windows security protection that was set in place. I am unable to access a com object created by a script. http://stackoverflow.com/a/14996243/945456 – Powerboy2 Jan 27 '17 at 08:19

1 Answers1

0

It seems that your getElementByID is working fine, but your variables are not set so you are setting the value of the Username and Password fields on the web page to "" (the value of $x and $y).
Try this out and see if you get better results. Change the OK button to:

$OKButton.Add_Click({$objForm.Close()})

Then after you make your call to show the form set $x and $y like:

[void] $objForm.ShowDialog()

$x=$objTextBox1.Text
$y=$objTextbox2.Text

That should take care of it as far as I can tell, but without having a login for the site I am unable to be 100% sure.

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
  • I made the suggested changes but it looked like it was posting the $x, and $y before. However I believe this might be a failure to launch due to permissions set on the box restricting me from changing the protection level of IE. – Powerboy2 Mar 18 '14 at 00:15