I cannot display the modification date of a directory with powershell

Asked

Viewed 171 times

1

Hello, I am trying to display the date of creation and modification of a directory using the powershell, I am using the command:

Get-WmiObject Win32_Directory -filter 'Drive="C:" and Path="\\"' -ComputerName MyPC |
select FileName,LastModified -First 3

but the return I have is a string:

FileName                         LastModified             
--------                         ------------             
$recycle.bin                     20151022091602.219458-120
0f74e86e50f02a5493eece53fbe1da58 20141005215102.861881-180
384d408957a87176de               20141004215102.325431-180

How to display the date or to convert these string to date?

2 answers

1

You can use the Get-Itemproperty.
Ex:

(Get-ItemProperty C:\Temp).CreationTime
Monday, March 30, 2015 20:15:55

(Get-ItemProperty C:\Temp).LastWriteTime
Thursday, January 7, 2016 17:56:06

  • The command doesn’t work when I want to get the information from a remote machine. For that I would have to use invoke-comand, but I was able to format the output to the pattern I wanted.

0


I got the information I wanted by formatting the output generated with the following code:

Get-WmiObject Win32_Directory -filter 'Drive="D:" and Path="\\users\\"' -ComputerName $HostName | sort LastModified -Descending | select -First 3 | foreach{
   $newObj = "" | select Name,LastModified,hostname
   $newObj.Name = $_.Name
   $newObj.LastModified = $_.LastModified.Substring(0,8).Insert(4,"/").Insert(7,"/")
   $newObj.hostname = $HostName

   $newObj
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.