header image

Folder creation dates from WMI

Posted by: | April 14, 2016 Comments Off on Folder creation dates from WMI |

A question on the powershell.org about finding the creation date of folders raises some interesting points

 

To find a folder’s creation date use:

Get-WmiObject -Class Win32_Directory -Filter "Drive=’C:’ AND Path = ‘\\users\\$user\\’" | select Name, @{N=’Creation date’; E={$_.ConvertToDateTime($_.CreationDate)}}

 

OR

 

Get-CimInstance -ClassName Win32_Directory -Filter "Drive=’C:’ AND Path = ‘\\users\\$user\\’" | select Name, CreationDate

 

If you use Get-WmiObject the date is returned in the form

20160128110039.938756+000

 

Which is why you need to perform the conversion using the ConvetToDateTime method that PowerShell adds to every WMI object.

 

Get-CimInstance automatically performs the conversion for you.

 

The other interesting part is the filter

"Drive=’C:’ AND Path = ‘\\users\\$user\\’"

 

Note that it’s wrapped in double quotes. Each of the values is a string so HAS to be in single quotes. Also note that you need to double the \ characters as WMI treats a single \ as an escape character so you have to escape the escape character.

under: PowerShell and CIM, PowerShell and WMI, PowerShell Basics

Comments are closed.

Categories