WMI Query folder created date


This topic contains 8 replies, has 4 voices, and was last updated by Profile photo of Richard Diphoorn Richard Diphoorn 5 months, 2 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #37752
    Profile photo of john kelly
    john kelly


    Ive been going around in circles with this one

    Ive readup on WMI and trid tweaking examples online to no avail. Im using WMI as it has remoting capablities.

    I need to query the date a folder was created i tried a zillion different combinations but cant get it to work. My last attempt that demonstrates my thinking is below is below

    Get-WmiObject Win32_Directory -computername $computer -filter 'Drive="C:" and Path="\\users\$user"' | select-object creationdate

    I need to get the folder date of the user folder and then intend to round of the date then compare this with the dates of other users folders and select the oldest.

    I tried get-item etc. but I'm not aware of any PowerShell cmdlet that will let me get this info remotely.

    I'm using powershell 4

    I dont want to tamper with the remote machines settings regarding winrm windows remoting so wont be using invoke-command on this occasion

    Let me know where im going wrong


    Profile photo of Dave Wyatt
    Dave Wyatt

    Try this:

    Get-WmiObject Win32_Directory -ComputerName $computer -Filter "Name = 'C:\\users\\$user'" |
    Select-Object -ExpandProperty CreationDate

    The date will be in WMI format. To translate:

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


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

    Profile photo of john kelly
    john kelly


    Ive tried below

    Get-WmiObject Win32_Directory -ComputerName $computer -Filter "Name = C:\\users\\$user" | Select-Object -ExpandProperty CreationDate

    Got the error below

    Get-WmiObject : Invalid query "select * from Win32_Directory where Name=c:\\users\\bicard"
    At line:1 char:1
    + Get-WmiObject Win32_Directory -computername win7vm2-pc -filter "Name=c:\\users\\ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    That particular error has occurred with many other attempts. Does it have to do with the creation date being an array. iw ould imagine the creationdate property is one object ?

    Profile photo of Dave Wyatt
    Dave Wyatt

    Hmm, that's odd. There should be single quotes around 'c:\\users\\$user'. I'm not sure if I forgot to type them, or if our forum software is being "helpful" again. 🙂


    Its down to the single quotes being missing. CreationDate is a single date time value

    Name : CreationDate
    Value :
    CimType : DateTime
    Flags : Property, ReadOnly, NullValue
    Qualifiers : {read}
    ReferenceClassName :

    the format is specific to WMI

    Profile photo of john kelly
    john kelly

    That work great now Dave 🙂 thanks. I'm blaming my fuzzy monitor display for not seeing those ' '

    Where I was going wrong is with the double backslashes in the in the path c:\\users\\bicard"

    Thanks for info Richard. I'm gonna run through those Shortly

    Profile photo of Dave Wyatt
    Dave Wyatt

    Not your fault, the quotes really were missing (probably my mistake). I edited my original post to add them in.

    Profile photo of Richard Diphoorn
    Richard Diphoorn

    Maybe you can revert to CIM, like this:

    Get-CimInstance -Query "ASSOCIATORS OF {Win32_Directory.Name='C:\Users\$user'} Where ResultClass = CIM_Directory"  | Select-Object Name,CreationDate

    Source: http://www.jaapbrasser.com/tag/cim_directory/

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.