PowerShell Guru - Request
I'm curious if any of the PowerShell Guru's would help me with a request.
I have a script I use once in awhile that I'd like to be setup in a GUI style.
Script just "extends" the users password. Basically just resets the Last Reset Date. Currently I have to "edit" and then enter the username, save it then run the script. I'd love it if I could just have a Username Box and a Run Button so i can just open it up type the username, and hit run then it executes the script. Any takers for help ?? :)
Import-Module ActiveDirectory
$users = "gerdesa" # enter USERNAME
foreach ($user in $users)
{
Get-ADUser $user | Set-ADAccountControl -PasswordNeverExpires $false
$TargetUser = Get-ADUser -Filter {sAMAccountName -eq $user}
$uObj = [ADSI]"LDAP://$TargetUser"
$uObj.put("pwdLastSet", 0)
$uObj.SetInfo()
$uObj.put("pwdLastSet", -1)
$uObj.SetInfo()
}
Comments
Give me an hour or two.
Stephen to the rescue! You are a very handy person to have lingering the Forums!! Thank you so much for all the help with PowerShell related things.
Actually Just do this:
[array]$users = (Read-Host "Enter Usernames separated by a comma:").Split(",") | % { $_.Trim() }
When you run the script it'll prompt for the users you want to change, comma separated-like. this becomes either a single or multiple member array depending on how many users you enter. The rest of your code will work as advertised.
There. 8 minutes. That's not too bad for turn around time :)
Basically this: Just add the code at the top?
[array]$users = (Read-Host "Enter Usernames separated by a comma:").Split(",") | % { $_.Trim() }
Import-Module ActiveDirectory
$users = "gerdesa" # enter USERNAME
foreach ($user in $users)
{
Get-ADUser $user | Set-ADAccountControl -PasswordNeverExpires $false
$TargetUser = Get-ADUser -Filter {sAMAccountName -eq $user}
$uObj = [ADSI]"LDAP://$TargetUser"
$uObj.put("pwdLastSet", 0)
$uObj.SetInfo()
$uObj.put("pwdLastSet", -1)
$uObj.SetInfo()
}
If you use "param ()" you can take command line parameters.
Now you should be able to run the script like this:
Replace
$users = "gerdesa" # enter USERNAME in your code with the line I sent you.
Oops, $users should probably be an array.
Gah, I really should test things before posting them. It's $(throw, not ($throw
Also, you don't have to wrap the parameters in quotes.
Dan,
Did you get this working?
Yes, it loads up asking for the username. Not as pretty as a Full GUI, but it will certainly work. Much easier than - right click / edit / remove old name / add new name / save / right click run with powershell.
Thanks for the suggestion! Never would've gotten that without help!
If you ask *really* nicely I'll package a GUI for you in my copy of Powershell Studio and give you a link to it via my GitHub.
Great. Now I have to do it. *sigh*.....coming right up.
Dan,
Turns out you picked the day that my Powershell Studio license expired haha. I'll have this for you once our Business Office processes the payment. Should be tomorrow. I'll make it be then lol. I need it back!
haha what are the odds. I was just looking at that peice of software. It looks amazing for people who deal in powershell all the time.
It's done and tested. I just can't build it without a stupid licensing warning popping up when you run the executable. Once I have the new license it'll build it and get rid of that, and that's the version I'll give you.
Here it is though:
haha That's awesome!
I aim to please. Shipping to you soon :)
We can remove the picture thought right :) :P I'm sure the other 2 people that assist don't want to see my Face everytime they have to extend a password :)
I'll think about it. :) I'm just kidding. It'll be gone in the version you get. I was just dicking around with you. I'll even name it something professional!
It is a good picture though...Almost Facebook Worthy but didn't make the cut.
I have my license back! Real quick before I do the final build.....do you have an icon file you'd like me to use? Maybe a company logo?
We do have a LOGO, if that can be incorperate...Sure why not!!
https://github.com/steviecoaster/Powershell/blob/master/Sadler.zip
Should be able to download that.The executable should be all you need to worry about, but I gave you the source code too incase you ever decide to get Powershell Studio :)
Double click and run PS Password Expiration Utility.exe and test it out. Let me know if you get any funky errors. I tested it with some Write-Hosts, but didn't test the actual code against my AD, for reasons haha.
On A Server 2008 R2 machine i get the following Error. But I was able to load it on our 2012 Server it worked just fine so far!
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: PS Password Expiration Utility
Problem Signature 02: 1.0.0.7
Problem Signature 03: 57a9c0dd
Problem Signature 04: PoshExeHostWinV3
Problem Signature 05: 1.0.0.7
Problem Signature 06: 57a9c0dd
Problem Signature 07: 94
Problem Signature 08: 89
Problem Signature 09: System.IO.FileNotFoundException
OS Version: 6.1.7601.2.1.0.272.7
Locale ID: 1033
Additional Information 1: e6e6
Additional Information 2: e6e6c208b90db2aa028f8f653cabbf23
Additional Information 3: f3f8
Additional Information 4: f3f81af0c125b5f6031976d9c59b8d7a
This is amazing though..I've tested with 4 "test" users and it works amazing on the 2012 Server. Soooo much easier. I can't even thank you enough for this.
What version of .Net Framework is on the 2008 R2 box? It's definitely something with the .Net versions.
If you have Remote Server Admin Tools on your local machine, you can use the utility from there too. the AD Powershell module gets installed as part of that, barring of course that you have elected to install the AD DS tools as part of the RSAT installation :).