WMI Query folder created date

Tagged: 

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

  • Author
    Posts
  • #37752
    Profile photo of john kelly
    john kelly
    Participant

    Hi

    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

    Thanks

  • #37754
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Try this:

    Get-WmiObject Win32_Directory -ComputerName $computer -Filter "Name = 'C:\\users\\$user'" |
    Select-Object -ExpandProperty CreationDate
    
  • #37755
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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)}}

    OR

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

  • #37756
    Profile photo of john kelly
    john kelly
    Participant

    Hi

    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 ?

  • #37757
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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. 🙂

  • #37760
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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

  • #37762
    Profile photo of john kelly
    john kelly
    Participant

    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

  • #37763
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

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

  • #37764
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    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/

You must be logged in to reply to this topic.