Find latest modified file information in PowerShell
Are you sure that what you are trying to do is not the following?
Get-ChildItem 'C:\Test Folder' | Sort {$_.LastWriteTime} | select -last 1
You can try this:
$c = Get-ChildItem 'C:\Test Folder' | Sort {$_.LastWriteTime} | select -last 1 | foreach {$a=$_;$b=Get-Acl $_.FullName; Add-Member -InputObject $b -Name "LastWriteTime" -MemberType NoteProperty -Value $a.LastWriteTime;$b}
$c.LastWriteTime
So the select will allow you to just get the properties you are interested in.
So a few things to do:
- Figure out what properties you could select from
Get-ChildItem | Get-Member -membertype properties
Once you know the properties just add to the select in your original statement
Get-ChildItem'c:\test folder' | where {$_.lastwritetime} | select -last 1 | ` foreach { write-host $_.lastwritetime ((get-ACL).owner)}
Finally, don't be afraid of the Get-Help command.