Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, November 19, 2012 12:14 PM
Hello
I want to create a list of folders, their nested folder and files under each folder alongwith their file attributes like
- FileName
- Location
- Size
- FileType
- LastModifiedBy (Username who modified the file last time)
- WindowsModified (Last Modified Date)
- WindowsCreatedBy(Username who create the file)
- WindowsCreated (File Created Date)
- AccessedDate (Last Assessed Date)
- MD5Key (Generate MD5 hash key depending on file content)
How can I generate this information and save it into CSV file?
I want execute the scrpit like this fileassess.ps1 -path "c:\
Regards
Avian
All replies (8)
Saturday, November 24, 2012 5:42 AM ✅Answered
Hi
Have you read these posts:
-http://stackoverflow.com/questions/251851/using-powershell-to-add-an-extension-to-files
http://tfl09.blogspot.com/2012/02/get-childitem-and-theinclude-and-filter.html
Regards,
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Monday, November 19, 2012 12:55 PM
Start with:
Get-Help Get-Childitem
Get-Help Select-Object
Get-Help Export-Csv
Grant Ward, a.k.a. Bigteddy
Monday, November 19, 2012 1:09 PM
Thanks for help. I am using following script from http://www.gotitsolutions.org/2010/01/30/data-profiling-with-windows-powershell/. Seems to be working, now I am looking for found a solution for generating MD5Hash key and adding in CSV file. ANy Idea how can I do this?
#Set-Location -Path "c:\powershell\"#Set-ExecutionPolicy Unrestricted# . c:\powershell\Untitled1.ps1$root = "c:\\myfiles"$report = ".\report.csv"$AllFiles = @()foreach ($file in get-childitem $root -recurse| Select-Object FullName, Root, Directory, Parent, Name, Extension, PSIsContainer, IsReadOnly, Length, CreationTime, LastAccessTime, LastWriteTime, Attributes){$acl = get-acl $file.fullname | select-object path,owner,accesstostring,group$obj = new-object psObject$obj | Add-Member -membertype noteproperty -name FilePathandName -Value $file.FullName$obj | Add-Member -membertype noteproperty -name Root -Value $file.Root$obj | Add-Member -membertype noteproperty -name Ditrectory -Value $file.Directory$obj | Add-Member -membertype noteproperty -name Parent -Value $file.Parent$obj | Add-Member -membertype noteproperty -name Name -Value $file.Name$obj | Add-Member -membertype noteproperty -name Extension -Value $file.Extension$obj | Add-Member -membertype noteproperty -name IsDIR -Value $file.PSIsContainer$obj | Add-Member -membertype noteproperty -name IsReadOnly -Value $file.IsReadOnly$obj | Add-Member -membertype noteproperty -name Size -Value $file.Length$obj | Add-Member -membertype noteproperty -name CreationTime -Value $file.CreationTime$obj | Add-Member -MemberType noteproperty -Name LastAccessTime -Value $file.LastAccessTime$obj | Add-Member -MemberType noteproperty -Name LastWriteTime -Value $file.LastWriteTime$obj | Add-Member -MemberType noteproperty -Name Attributes -Value $file.Attributes$obj | Add-Member -MemberType noteproperty -Name Path -Value $file.path$obj | Add-Member -MemberType noteproperty -Name Owner -Value $acl.owner$obj | Add-Member -MemberType noteproperty -Name AccessToString -Value $acl.accesstostring$obj | Add-Member -MemberType noteproperty -Name Group -Value $acl.group$AllFiles += $obj}$AllFiles |Export-Csv $report –NoTypeInformation
Monday, November 19, 2012 1:25 PM
$hasher = [System.Security.Cryptography.MD5]::Create()
foreach ($file in get-childitem $root -recurse)
{
$acl = get-acl $file.fullname | select-object path,owner,accesstostring,group
$obj = new-object psObject
$obj | Add-Member -membertype noteproperty -name FilePathandName -Value $file.FullName
$obj | Add-Member -membertype noteproperty -name Root -Value $file.Root
$obj | Add-Member -membertype noteproperty -name Ditrectory -Value $file.Directory
$obj | Add-Member -membertype noteproperty -name Parent -Value $file.Parent
$obj | Add-Member -membertype noteproperty -name Name -Value $file.Name
$obj | Add-Member -membertype noteproperty -name Extension -Value $file.Extension
$obj | Add-Member -membertype noteproperty -name IsDIR -Value $file.PSIsContainer
$obj | Add-Member -membertype noteproperty -name IsReadOnly -Value $file.IsReadOnly
$obj | Add-Member -membertype noteproperty -name Size -Value $file.Length
$obj | Add-Member -membertype noteproperty -name CreationTime -Value $file.CreationTime
$obj | Add-Member -MemberType noteproperty -Name LastAccessTime -Value $file.LastAccessTime
$obj | Add-Member -MemberType noteproperty -Name LastWriteTime -Value $file.LastWriteTime
$obj | Add-Member -MemberType noteproperty -Name Attributes -Value $file.Attributes
$obj | Add-Member -MemberType noteproperty -Name Path -Value $file.path
$obj | Add-Member -MemberType noteproperty -Name Owner -Value $acl.owner
$obj | Add-Member -MemberType noteproperty -Name AccessToString -Value $acl.accesstostring
$obj | Add-Member -MemberType noteproperty -Name Group -Value $acl.group
if(!$file.PsIsContainer)
{
$inputStream = New-Object IO.StreamReader $file.fullname
$hashBytes = $hasher.ComputeHash($inputStream.BaseStream)
$inputStream.Close()
$builder = New-Object System.Text.StringBuilder
$hashBytes | Foreach-Object { [void] $builder.Append($_.ToString("X2")) }
$obj | Add-Member -MemberType noteproperty -Name MD5Hash -Value $builder.ToString()
}
$AllFiles += $obj
}
Monday, November 19, 2012 1:46 PM
Kazun I tested but MD5 values are not adding in CSV file, However $builder.ToString showing the values. Am I missing anything?
I also want to add more parameter like
IncludeExtension - *.doc;*.docx or any extension - That means it will validate and add those file which matches file parameter with IncludeExtension parameter values
ExcludeExtension - *.exe;*.pst or any extension - That means it will validate and skip those file which matches file parameter with ExcludeExtension parameter values
Secondly I also want to pass parameter for username, password and domain, so only authorised user can access the folder from where we want to read files.
Please advise.
Avian
Tuesday, November 20, 2012 6:09 AM
Has anyone can help me on above mentioned issue?
Friday, November 23, 2012 8:40 AM
Hi,
Wish below post/Blog can help you:
http://blog.brianhartsock.com/2008/12/13/using-powershell-for-md5-checksums/
Regards,
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Friday, November 23, 2012 1:25 PM
Hi Peterson
I already saw this url and implemented MD5 functionality also, but still struggling on following. Please advise
IncludeExtension - *.doc;*.docx or any extension - That means it will validate and add those file which matches file parameter with IncludeExtension parameter values
ExcludeExtension - *.exe;*.pst or any extension - That means it will validate and skip those file which matches file parameter with ExcludeExtension parameter values
Secondly I also want to pass parameter for username, password and domain, so only authorised user can access the folder from where we want to read files.