Solved

Powershell script to Return AD's password status and ask if maintainer wants to change it.

Posted on 2011-02-11
8
944 Views
Last Modified: 2012-05-11
Experts,

        I have a script that searches for an AD user and returns the users path and properties. I want the same script to include the users password status and ask the maintainer if they would like to change password at this time. Password activity needs to be piped out to text file.

        Here is the code I have so far...
$Search = New-Object DirectoryServices.DirectorySearcher([ADSI]“”)
$Search.filter = “(&(objectClass=user)(sAMAccountName=$User))”
$Search.Findall()

Open in new window

0
Comment
Question by:missymadi
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:alreadyinuse
ID: 34875526
If your clients are in a domain ,GPO notifications presented on the clients desktop x number of days before it expires. Then they can change them from their workstations.
0
 

Author Comment

by:missymadi
ID: 34875577
This notification needs to be executed immediately. The purpose of the script is for the maintainer to run this script and have a report (printable) and an option to immediately change the password.
0
 
LVL 5

Expert Comment

by:alreadyinuse
ID: 34875669
0
 
LVL 5

Expert Comment

by:alreadyinuse
ID: 34875686
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 34876357
What information are you looking to get?
The quest cmdlets can probably do what you are looking for.

$user = read-host "Enter UserName"
Get-qaduser $User | Select PasswordLastSet, PasswordAge,PasswordExpires, PasswordNeverExpires, UserMustChangePassword, PasswordIsExpired, PasswordStatus
0
 

Author Comment

by:missymadi
ID: 34883527
Here is the code I have so far. I have not tested in our lab as of yet.
What is the format/syntax to pipe the user information into a text file?

Thanks, Missymadi
$user = read-host "Enter UserName"
Get-qaduser $User | Select PasswordLastSet, PasswordAge,PasswordExpires, PasswordNeverExpires, UserMustChangePassword, PasswordIsExpired, PasswordStatus 
$User = read-host "Do you want to reset a user's password?"
$strResponse = Read-Host "[1] Yes, [2] No"

If ($strResponse -eq "1" $colComputers = ListComputers | Sort-Object}
***I want to run another script to reset user's password
$users = get-qaduser -samaccountname USERNAME 
$users | %{
set-qaduser -Userpassword 'Test'
get-qaduser -samaccountname $_.samaccountname | Select samaccountname, passwordlastset | out-file c:\PwdChanged.txt -noclobber
}

   else{Write-Host "Good-Bye"

Open in new window

0
 

Author Comment

by:missymadi
ID: 34883553
Nevermind - I had the password file in there ;)

I am going to test the code in our lab now.
0
 

Author Comment

by:missymadi
ID: 34883891
The reason for this script - we have a test LAN, and this script will come in handy to see test user stats and quickly(automatically) reset test users passwords.

Here is my code for the Powershell script. It is not executing how I expected.

1. Enter a username and the username entered password information will be returned.
2. The user is asked if they want to reset a user's password in AD. The reponse should be 1 for yes, 2 no
3. If user entered 1, enter user name and the script will change the users password. The password information should be printed to screen and to out.txt file so the user knows the new password.

$user = read-host "Enter UserName"
Get-qaduser $User | Select PasswordLastSet, PasswordAge,PasswordExpires, PasswordNeverExpires, UserMustChangePassword, PasswordIsExpired, PasswordStatus 
$User = read-host "Do you want to reset a user's password?"
$strResponse = Read-Host "[1] Yes, [2] No"

If ($strResponse -eq "1" )

{$users = get-qaduser -samaccountname USERNAME 
$users | %{
set-qaduser -Userpassword 'Test'
get-qaduser -samaccountname $_.samaccountname | Select samaccountname, passwordlastset | out-file c:\PwdChanged.txt -noclobber
}

   else{Write-Host "Exiting Search Script"}
}

Open in new window

0

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now