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();
}