<#Read Me
Script Usage - Finding UserID password related details such as -
1. Password Expired or not ?
2. If Expired, then on which day it's going to expired ?
3. How many days left before it expires ?
4. Whether UserId is active or not ?
Note - Input.txt contains Samaccountname of all the users against which you are looking to get info.
Input.txt should be in the same location of script.
Refer Userdetails_$date.csv for detailed output.
**************************************************************************#>
$inputuserids = Get-Content ./Input.txt
$date = $(Get-Date -Format "dd_MM_yyy")+".csv"
foreach($userid in $inputuserids)
{
try{
Get-ADUser -Identity $userid -Properties Displayname,msDS-UserPasswordExpiryTimeComputed,PasswordExpired,Enabled,`
Passwordlastset | Select Displayname,Samaccountname,@{n="AccountStatus";e={if($($_.Enabled) -eq $true){"Active"}else{"Disabled"}}},`
Passwordlastset,PasswordExpired,@{n="ExpiryDate";e={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}},`
@{n="DaysLeft";e={(New-TimeSpan -Start $(Get-Date) -End $([datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed"))).Days}}`
| Export-Csv ./Userdetails_$date.csv -NoTypeInformation -Append
}
catch
{
$userid | Select-Object -Property @{n="Displayname";e={"NA"}},@{n="Samaccountname";e={$userid}},@{n="AccountStatus";e={"NA"}},@{n="Passwordlastset";e={"NA"}},@{n="PasswordExpired";e={"NA"}},@{n="ExpiryDate";e={"NA"}},@{n="DaysLeft";e={"NA"}}| Export-Csv ./Userdetails_$date.csv -NoTypeInformation -Append
}
}
Sample Output
No comments:
Post a Comment