WMI Query folder created date

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

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

OR

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

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 ?

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. :slight_smile:

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

That work great now Dave :slight_smile: 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

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

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/