Monthly Archive


W2KSG: Folders Creation date

WMI has a class Win32_Directory for working with folders on a machine. We can use this class to find all folders created this month.

Listing 6.22

$d = "'" + (Get-WmiObject -Class Win32_Directory -Filter "name='c:\\'").ConvertFromdateTime([datetime]"09/01/2008") + "'"
Get-WmiObject -Class Win32_Directory -Filter "CreationDate > $d" | Select Name, CreationDate

We start by creating a date in WMI format.  We use the Win32_Directory WMI class and filter on the root folder for speed. Note that we have to use \\ instaed of \ when dealing with file paths in WMI.  We then use the ConvertFromDateTime method to put the required date into WMI format.  The date will look like this


Note that we have put ' ' round the date.  This is needed for the correct formatting of the WMI query.

We then use Win32_Directory again and filter based on dates greater than our test date i.e. folders created this month.

The really great thing about this is that we could use -computername to specify a remote machine. We could modify the script to read a file of machine names and test our servers for new folders.


Share this post :

Technorati Tags: PowerShell,WMI

Leave a Reply