Parity123
asked on
Powershell: Password report
Hello,
I have the following code to get the password expiration report. I need assistance in modifying the code to get just the total counts of users password expiring on a specific date. For instance: 01/01/2016
Import-Module ActiveDirectory
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and physicalDeliveryOfficeName -like "*" } `
–Properties "SamAccountName","mail","p wdLastSet" ,"physical deliveryof ficename", "msDS-User PasswordEx piryTimeCo mputed" |
Select-Object -Property "SamAccountName","mail","p hysicaldel iveryoffic ename",@{N ame="Passw ord Last Set";`
Expression={[datetime]::Fr omFileTime ($_."pwdLa stSet")}}, @{Name="Password Expiry Date";`
Expression={[datetime]::Fr omFileTime ($_."msDS- UserPasswo rdExpiryTi meComputed ")}} |
Export-CSV "C:\PasswordExpirationRepo rt.csv" -NoTypeInformation -Encoding UTF8
I have the following code to get the password expiration report. I need assistance in modifying the code to get just the total counts of users password expiring on a specific date. For instance: 01/01/2016
Import-Module ActiveDirectory
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and physicalDeliveryOfficeName
–Properties "SamAccountName","mail","p
Select-Object -Property "SamAccountName","mail","p
Expression={[datetime]::Fr
Expression={[datetime]::Fr
Export-CSV "C:\PasswordExpirationRepo
So you're going to specify the date when calling the function, and it should in turn return the number of days before the password expires based on the date you specify?
ASKER
I can specify the date with a variable in the code.
$mydate="01/01/2016"
and I want the total count of users password expiring on this date.
$mydate="01/01/2016"
and I want the total count of users password expiring on this date.
should that include all passwords that have already expired or just passwords expiring on that exact date?
ASKER
just on that exact date.
This is what I have so far. It's late and I'm beat so I'll pick it up again tomorrow. Feel free to modify as needed, but honestly I feel like I'm off track on this one:
[datetime]$date = Read-Host 'Enter date'
$expiry = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties 'DisplayName', 'msDS-UserPasswordExpiryTimeComputed' | Select-Object -Property 'DisplayName',@{n='ExpirationDate';e={[datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}}
foreach ($i in $expiry) {
if ($i.ExpirationDate -eq $date) {
Write-Host $i
}
}
ASKER
Thanks Jason. I tried.
For instance: The value for $i.ExpirationDate is 1/5/2016 9:50:54 AM.
I set the variable $mydate="1/5/2016" just to try
and I changed the code to if ($i.ExpirationDate -contains $mydate) and it does not return anything.
For instance: The value for $i.ExpirationDate is 1/5/2016 9:50:54 AM.
I set the variable $mydate="1/5/2016" just to try
and I changed the code to if ($i.ExpirationDate -contains $mydate) and it does not return anything.
Yea I tried to be as upfront as I could that it was an untested script. I just wanted to put something out there we can use to build on. I have three Exchange migrations I'm working on at the moment and I just couldn't look at my computer any longer last night. I'll edit the script and have an updated version to you by the end of the day.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried and does not return any values. some if the values are
12/22/2015 10:35:14 AM
1/9/2016 4:30:10 PM
12/26/2015 8:46:00 AM
2/7/2016 1:31:40 PM
2/5/2016 10:11:07 AM
12/26/2015 12:08:11 AM
I think the issue is comparison. I even hardcoded the date to $mydate="2/5/2016", and used -contains $mydate and does not return values.
12/22/2015 10:35:14 AM
1/9/2016 4:30:10 PM
12/26/2015 8:46:00 AM
2/7/2016 1:31:40 PM
2/5/2016 10:11:07 AM
12/26/2015 12:08:11 AM
I think the issue is comparison. I even hardcoded the date to $mydate="2/5/2016", and used -contains $mydate and does not return values.
That's odd we're seeing different results. I'll keep working on it today. What PowerShell version are you using? Just run this command to check:
$PSVersionTable.PSVersion
$PSVersionTable.PSVersion
ASKER
V4.0
ASKER
Can someone please assist. Thanks.