Solved

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

Posted on 2011-02-11
8
953 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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