611646 (3) [Avatar] Offline
#1
Hello,

I am a newbie to PowerShell and was wondering how can I write a Script that will cycle thru a Directory and its SubDirectories and produce a list of all the Files and their Attributes. I have been able to cycle thru the Directory/SubDirectories/Files but I have not been able to get all of the File Attributes.

Any help would be greatly appreciated.

Tim Curwick (4) [Avatar] Offline
#2
No need to cycle through the directories, as Get-ChildItem has a switch parameter -Recurse to do that for you. Switch parameter -File will give you just the files and not the folders. Pipe to Select-Object to get just the properties you need. For example:

$Path = "C:\MyRootDirectory"
Get-ChildItem -Path $Path -File -Recurse | Select-Object -Property DirectoryName, Name, Attributes
611646 (3) [Avatar] Offline
#3
Tim,

I want to thank you for your reply to my question and state that I had found the "-Recurse" option in the book. However what I really need to find out is all of the File Information Attributes that are available to return - you mentioned a few ( DirectoryName, Name, Attributes ).

Below is a Script that I wrote, that gets a lot of the information on each file, but what I want to know is this all of the information that I can get on a File, or is there more that can be obtained, and if so where would I find out what it is?

Get-ChildItem -Path C:\Windows -Filter *.* -File | Select-Object
@{Name="File";Expression={$_.VersionInfo.File}}
, @{Name="InternalName";Expression={$_.VersionInfo.InternalName}}
, @{Name="OriginalFileName";Expression={$_.VersionInfo.OriginalFileName}}
, @{Name="FileVersion";Expression={$_.VersionInfo.FileVersion}}
, @{Name="FileDescription";Expression={$_.VersionInfo.FileDescription}}
, @{Name="Product";Expression={$_.VersionInfo.Product}}
, @{Name="ProductVersion";Expression={$_.VersionInfo.ProductVersion}}
, @{Name="Debug";Expression={$_.VersionInfo.Debug}}
, @{Name="Patched";Expression={$_.VersionInfo.Patched}}
, @{Name="PreRelease";Expression={$_.VersionInfo.PreRelease}}
, @{Name="PrivateBuild";Expression={$_.VersionInfo.PrivateBuild}}
, @{Name="SpecialBuild";Expression={$_.VersionInfo.SpecialBuild}}
, @{Name="Language";Expression={$_.VersionInfo.Language}}
, BaseName
, Mode
, Name
, Length
, DirectoryName
, Directory
, IsReadOnly
, Exists
, FullName
, Extension
, CreationTime
, CreationTimeUTC
, LastAccessTime
, LastAccessTimeUTC
, LastWriteTime
, LastWriteTimeUTC
, Attributes
, LegalCopyright
, LegalTradeMark | Export-Csv Directory_Listing_1.csv