Manny-Tech Posted January 10, 2020 Posted January 10, 2020 Hi, I'm attempting to output the msDS-UserPasswordExpireTimeComputed attribute into a readable format. So far I can achieve this by doing the below: (Get-ADUser ($env:UserName) -Properties msDS-UserPasswordExpiryTimeComputed).'msDS-UserPasswordExpiryTimeComputed' | ForEach-Object -Process {[datetime]::FromFileTime($_)} | Out-File -encoding {ascii} (Join-Path $Env:USERPROFILE 'pwdexpiry.txt' ) However, it does leave a blank line at the top of the txt file which I could do without. I think the blank line is coming from the below because if I remove that part it doesn't insert a blank line at the top of the output, however the date then isn't in a reable format.ForEach-Object -Process {[datetime]::FromFileTime($_)} I'm sure it's a simple fix for someone more clued up on PowerShell than I. Any help muchly appreciated.
fordea Posted January 10, 2020 Posted January 10, 2020 (edited) It's to do with the way Powershell outputs a DateTime object (for instance if you do a Get-Date in the console notice how there is a blank line before the date is printed and then two blank lines after it. This should mimic the output you're getting in the file). If you create a string representation of the date beforehand it should work: [datetime]::FromFileTime($_).ToString() Edited January 10, 2020 by fordea 1
Manny-Tech Posted January 10, 2020 Author Posted January 10, 2020 Fantastic! That works. Now all I need to do is get this to run as a user logs in and I can then display the text with BGInfo for password expiry. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now