Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

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

0

Comments

39 comments
Date Votes
  • Give me an hour or two.

    1
  • 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. 

    0
  • 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.

    0
  • There. 8 minutes. That's not too bad for turn around time :)

    0
  • 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()
    }

     
    0
  • If you use "param ()" you can take command line parameters.

    Import-Module ActiveDirectory

    param (
    [string]$users = ($throw "You must specify a list of users")
    )

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

    Now you should be able to run the script like this:

    .\script.ps1 "bob"
    .\script.ps1 "bob","jane","bill"

     

    0
  • Import-Module ActiveDirectory

    [array]$users = (Read-Host "Enter Usernames separated by a comma:").Split(",") | % { $_.Trim() }

    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()
    }
    0
  • Replace 

    $users = "gerdesa" # enter USERNAME in your code with the line I sent you.

    0
  • Oops, $users should probably be an array.

    Import-Module ActiveDirectory

    param (
    [array]$users = ($throw "You must specify a list of users")
    )

    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()
    }
    0
  • Gah, I really should test things before posting them. It's $(throw, not ($throw

    Import-Module ActiveDirectory

    param (
    [array]$users = $(throw "You must specify a list of users")
    )

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

    Also, you don't have to wrap the parameters in quotes.

    .\script.ps1 bob
    .\script.ps1 bob,jane,bill
    0
  • Dan, 

     

    Did you get this working?

    0
  • 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!

    0
  • 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.

    0
  • 0
  • Great. Now I have to do it. *sigh*.....coming right up.

    0
  • 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!

    0
  • 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.

    0
  • 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:

    0
  • haha That's awesome!

    0
  • I aim to please. Shipping to you soon :)

    0
  • 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 :)

    0
  • 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!

    0
  • It is a good picture though...Almost Facebook Worthy but didn't make the cut.

    0
  • 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?

    0
  • 0
  • We do have a LOGO, if that can be incorperate...Sure why not!!

    0
  • 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.

     

     

    0
  • 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

     

    0
  • 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.

    0
  • 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 :).

    0