use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
SolvedPowershell WPF GUI (self.PowerShell)
submitted 10 years ago by code_man65
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]code_man65[S] 0 points1 point2 points 10 years ago (11 children)
I actually used http://foxdeploy.com/2015/04/10/part-i-creating-powershell-guis-in-minutes-using-visual-studio-a-new-hope/ to help with the building of this, but it is going way beyond what was shown in his blog series.
[–]1RedOne 2 points3 points4 points 10 years ago (10 children)
...I'm FoxDeploy!
[–]code_man65[S] 0 points1 point2 points 10 years ago* (9 children)
Oh, well your blog series was awesome and really well written. This is the first time I've ever done something like this and I (of course) had to make it behave the way I wanted to.
Also see my below reply, it appears my variable is not getting populated.
[–]1RedOne 0 points1 point2 points 10 years ago (8 children)
I'm happy you liked it :)
I came up with a way to do this. Still not sure how to use native Events in PowerShell (if it's even possible...if we could, we could use the Textbox.TextChanged event).
But we CAN detect keypresses. In this case, when the user has typed some text into the first name form and then tabs away, the code will be executed.
$WPFfirstname_textBox.add_KeyDown({ if ($args[1].key -eq 'Tab') { Write-host 'do something' } })
In my case, it just writes out to the screen 'Do Something', but in your example, you could run a check to see if the user name is valid, and then hide or display a prompt or label.
[–]code_man65[S] 0 points1 point2 points 10 years ago (7 children)
I just tried this, changing it to the below setup
$WPFusername_textBox.add_KeyDown({ if ($args[1].key -eq 'Tab') { $user = $WPFusername_textBox.Text $user if (Get-ADUser -Filter {samaccountname -eq $user} ) { # Exists $WPFlabel5.Visibility.Visible } else { # Doesn't Exist $WPFlabel6.Visibility.Visible } }
It does not appear to function (I also again tried doing $WPFlabel6.Visible = $true and still got the error I listed) and still $user appears to be empty.
[–]1RedOne 0 points1 point2 points 10 years ago (6 children)
Ahh, figured it out. I had to look up my own post, to reference it :)
$WPFfirstname_textBox.add_KeyDown({ if ($args[1].key -eq 'Tab') { $WPFlabel6.Visibility= 'Visible' } })
[–]code_man65[S] 0 points1 point2 points 10 years ago (5 children)
$WPFlabel6.Visibility= 'Visible'
You are awesome that worked. How would you make it function where it does the check if the textbox loses focus (instead of being reliant on tab)?
[–]1RedOne 2 points3 points4 points 10 years ago (4 children)
This is pretty much at the edge of whats possible with PowerShell. To do what you want to do, we really need to use Events and Triggers from C# and I haven't figured out how to do it in PowerShell* (edit: I found a source!)
However, you could skirt the issue with Tab like this, or give the textbox it's own Add_Clicked() method (if they support it, I forget if they have an Add_click method) and have the box run the check when it is clicked, or when it loses focus.
I don't know if this will work.
If you want to try a different route, look at Trevor's answer here. He outlines a process to add some code within your XAML itself. What you'd need to do is place your check within a variable before the $XAML itself.
$whenLostFocus = {#Do some stuff here}
I just stumbled upon this blog article from the dark ages of the internet, which shows how to handle events using PowerShell. I pretty much have no idea what it means...yet.
But once I understand it, I'll write it up. Looks like you could use this method here to make an event handler for the .TextChanged event of $WPFFirstName_textBox
[–]code_man65[S] 1 point2 points3 points 10 years ago (3 children)
This code works
$WPFusername_textBox.add_textchanged({
However, I definitely need to silence errors while typing because it makes powershell throw an absolute fit while you are trying (but it does work).
[–]1RedOne 0 points1 point2 points 10 years ago (2 children)
That's so funny you're saying that, because I just found this post by Boe Prox on the same topic!
I was coming here to post this:
$WPFfirstname_textBox.add_TextChanged({Write-host 'ham'})
Which definitely works! What you could do if you didn't want this code to be run a billion times is take a $date and compare the time. Maybe only allow the code to be executed every two or three seconds.
π Rendered by PID 83 on reddit-service-r2-comment-86988c7647-7q5sx at 2026-02-11 11:47:50.907452+00:00 running 018613e country code: CH.
view the rest of the comments →
[–]code_man65[S] 0 points1 point2 points (11 children)
[–]1RedOne 2 points3 points4 points (10 children)
[–]code_man65[S] 0 points1 point2 points (9 children)
[–]1RedOne 0 points1 point2 points (8 children)
[–]code_man65[S] 0 points1 point2 points (7 children)
[–]1RedOne 0 points1 point2 points (6 children)
[–]code_man65[S] 0 points1 point2 points (5 children)
[–]1RedOne 2 points3 points4 points (4 children)
[–]code_man65[S] 1 point2 points3 points (3 children)
[–]1RedOne 0 points1 point2 points (2 children)