troubleshooting Question

Help With A PowerShell Script

Avatar of LindyS
LindySFlag for United States of America asked on
Active DirectoryPowershell
3 Comments1 Solution497 ViewsLast Modified:
I have a script that queries all of our DCs, looking for the lastlogon of specific users.
The user name is entered in a dialog box when the script is executed.
When the user is entered in the box, the box closes.

Is there a way to have the name entered in the script, and keep the box open to enter the next user name?

The script so far is as follows;

$today = Get-Date
$rundate = $($today.adddays(-0)).toshortdatestring()

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

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "User Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Enter the user name in the space below:"

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)

$objForm.Topmost = $True


$dcs = Get-Content "C:\temp\serverlist.txt"

 foreach($dc in $dcs){ get-QADUser $x  -Service $dc -Enabled -SearchRoot '' | Select-Object Name,sAMAccountName,Description,lastlogon  }
Write-Host "`nRun time was $(((get-date) - $today).totalseconds) seconds."
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros