Jump to content

Recommended Posts

Posted

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.

Posted (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 by fordea
  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...