I've been searching far and wide for explicit information on this, but I have not found any at all. Let's say I have a a file or a directory stored in the variable $Item
. Using Windows PowerShell (I am using 3.0), how can I get all of the metadata associated with $Item
that is not stored in its contents? For instance, I want to get it's permissions, its SID, its time of creation, its time of modification, the time it was last accessed, its attributes, and pretty much anything else that is displayed in the 'Properties' dialog box in Windows Explorer. I need to do this so I can record each item's properties in SVN metadata.
2 Answers
Assuming:
$item = Get-Item c:\windows\notepad.exe
Last access time:
$item.LastAccessTime.ToString()
Last modification time:
$item.LastWriteTime.ToString()
Creation time:
$item.CreationTime.ToString()
Attributes:
$item.Attributes
Version info:
$item.VersionInfo
The security permissions are not stored in the file, so you have to use the Get-Acl
cmdlet:
(Get-Acl $item).Access
you can get most of those elements from the System.IO.DirectoryInfo class
PS C:\Windows\system32> $([System.IO.DirectoryInfo]"c:\").creationtime
PS C:\Windows\system32> $([System.IO.DirectoryInfo]"c:\").Attributes
...
Here are the properties available from the object: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
now, I'm not sure what you mean by recursive, since you said you didn't want the contents of the directory, but you can get a list of sub items using .GetFiles or .GetDirectories. then you can recurse or iterate over them as you like.
-
1I use the word "recursively" because I need it to cycle through them automatically.– MelabMar 13, 2013 at 22:27