Author Posts

May 25, 2016 at 3:09 am

I am trying to convert the accountexpires property to something that is a date. I thought it might be the same as { [datetime]::fromFileTime($_.lastLogonTimestamp) } but it looks like this is not the case.

can anyone please advise? Thank you. in advance

$ADComputerProperties = @(# Hashtable for computer properties
	"Name",
	"SAMAccountName",
	"DNSHostName",
	"PasswordLastSet",
	"Enabled",
	"whenCreated",
	"accountExpires",
	"OperatingSystem",
	"OperatingSystemServicePack",
	"OperatingSystemVersion",
	"UserAccountControl",
	"LastLogonTimeStamp",
	"DistinguishedName"
)

$ADComputerPropertiesShown = @(# Hashtable for select 
	"Name",
	"SAMAccountName",
	"DNSHostName",
	"PasswordLastSet",
	"Enabled",
	"whenCreated",
	@{
		name = 'accountExpires';
		expression = { [datetime]::fromFileTime($_.accountExpires) }
	},
	"accountExpires",
	"OperatingSystem",
	"OperatingSystemServicePack",
	"OperatingSystemVersion",
	"UserAccountControl" 
	@{
		name = 'lastLogonTimestamp'; 
		expression = { [datetime]::fromFileTime($_.lastLogonTimestamp) }
	},
	"DistinguishedName"
)

Get-ADComputer -Filter { OperatingSystem -NotLike "*server*" } -Properties $ADComputerProperties | select $ADComputerPropertiesShown | Export-Csv "c:\temp\Justice_Desktop_Report-$filenamebit.csv"



	
			
	

May 25, 2016 at 3:58 am

If I perform this action on my local desktop:

(get-adcomputer $env:computername -Properties accountexpires).accountexpires | gm

((get-adcomputer $env:computername -Properties accountexpires).accountexpires).gettype()

I get a type of: TypeName: System.Int64

I wonder if this int value is a tick:

Looks like it is:
C:\Windows\System32\WindowsPowerShell\v1.0> (get-date).ticks
635997201401143677
C:\Windows\System32\WindowsPowerShell\v1.0> (get-date).ticks.gettype()

IsPublic IsSerial Name BaseType
——– ——– —- ——–
True True Int64 System.ValueType

$a = ((get-adcomputer $env:computername -Properties accountexpires).accountexpires)

New-Object System.DateTime $a

May 25, 2016 at 2:43 pm

Unless the expiration date is explicitly set, I don't believe you will get any results. I successfully ran your script without issue for a test server where I explicitly set the AccountExpirationDate.

Get-ADComputer TestServer-vt01 | Set-ADAccountExpiration -DateTime '01/01/2020' -WhatIf

You could also just use AccountExpirationDate in your return set.