Solved

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

Posted on 2011-02-11
8
951 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

810 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