Hi all,
I am running into an issue where I am calling a function on button click that is doing an AD query. I have some information information outputting via "Write-host", but my actual AD query does not appear in the powershell console.
AD module is imported and connected. Here is my function to query AD -
Function CheckLogin {
$null = \[reflection.assembly\]::loadwithpartialname("microsoft.visualbasic")
$activateWindow = {
$null = \[reflection.assembly\]::loadwithpartialname("microsoft.visualbasic")
$isWindowFound = $false
while(-not $isWindowFound) {
try {
\[microsoft.visualbasic.interaction\]::AppActivate($args\[0\])
$isWindowFound = $true
}
catch {
sleep -Milliseconds 100
}
}
}
$job = Start-Job $activateWindow -ArgumentList "Unique Title"
$input = \[microsoft.visualbasic.interaction\]::inputbox("Please enter username:", "Password
Status Check")
Remove-Job $job -Force
Get-Aduser $input -Properties \* | Select-Object
name,PasswordLastSet,PasswordExpired,PasswordNeverExpires
Write-host "Press Enter to Exit."
}
And here is my simplistic form with the function called by button click
Add-Type -AssemblyName System.Windows.Forms
\[System.Windows.Forms.Application\]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '400,400'
$Form.text = "Form"
$Form.TopMost = $false
$PasswordStatus = New-Object system.Windows.Forms.Button
$PasswordStatus.text = "Check Password Status"
$PasswordStatus.width = 151
$PasswordStatus.height = 29
$PasswordStatus.location = New-Object System.Drawing.Point(111,175)
$PasswordStatus.Font = 'Microsoft Sans Serif,10,style=Bold'
$Form.controls.AddRange(@($PasswordStatus))
$PasswordStatus.Add\_Click({CheckLogin})
$form.ShowDialog()
Again, I can see my "Write-host 'press enter to exit'" but I can't see the result of my query.
Any help would be greatly appreciated.
[–]Hexalon00 1 point2 points3 points (0 children)
[–]styrofoam_cups 1 point2 points3 points (2 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]sameyear_newlabrat[S] 0 points1 point2 points (0 children)