powershell to inventory a directory

Can any of you powersehll gurus provide a way to inventory a directory (windows server), and write the inventory to CSV file (including file name, full path, created, modified, accessed, and ideally MD5 hash). I would ideally like the results to be written to CSV/XLSX file, with a hyperlink to the files within the CSV file, so all the user needs to do is click the link within the spreadsheet that will open the file in the directory... Is this do-able?
LVL 3
pma111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prashant GirennavarCommented:
Are you referring to Active directory services from microsoft?

if yes , Do you want to query all the attributes of the objects in AD?

-Prashant Girennavar.
0
becraigCommented:
You can simply edit the fullname column to add the hyperlink in excel, I am looking at an easy way to do it.

$report = @()
gci C:\folder | where {$_.Psiscontainer -eq $false} | % {
write-host "Processing $_.Fullname"
$hashval = Get-FileHash $_.FullName | select -expa hash
$item = New-Object PSObject
$item | Add-Member -type NoteProperty -Name 'Name' -Value $_.Name
$item | Add-Member -type NoteProperty -Name 'Fullname' -Value $_.FullName
$item | Add-Member -type NoteProperty -Name 'CREATED' -Value $_.CreationTime
$item | Add-Member -type NoteProperty -Name 'ACCESSED' -Value $_.LastAccessTime
$item | Add-Member -type NoteProperty -Name 'MODIFIED' -Value $_.LastWriteTime
$item | Add-Member -type NoteProperty -Name 'FILEHASH' -Value $hashval
$report += $item
}

$report | Export-Csv report.csv -nti

Open in new window

0
pma111Author Commented:
>You can simply edit the fullname column to add the hyperlink in excel

Can you elaborate here as if you have hundreds of files that would take an age to manually hyperlink each file, or is there an automated way to do them in bulk?
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

becraigCommented:
Actually there is a really easy fix for this:

$report = @()
gci C:\users\v-craigw\Desktop | where {$_.Psiscontainer -eq $false} | % {
write-host "Processing $_.Fullname"
$hlink = '=HYPERLINK("'+$_.Fullname+'")'
$hashval = Get-FileHash $_.FullName | select -expa hash
$item = New-Object PSObject
$item | Add-Member -type NoteProperty -Name 'Name' -Value $_.Name
$item | Add-Member -type NoteProperty -Name 'Fullname' -Value $hlink
$item | Add-Member -type NoteProperty -Name 'CREATED' -Value $_.CreationTime
$item | Add-Member -type NoteProperty -Name 'ACCESSED' -Value $_.LastAccessTime
$item | Add-Member -type NoteProperty -Name 'MODIFIED' -Value $_.LastWriteTime
$item | Add-Member -type NoteProperty -Name 'FILEHASH' -Value $hashval
$report += $item
}

$report | Export-Csv report.csv -nti

Open in new window

0
pma111Author Commented:
Thanks becraig will give it a go shortly and feedback..
0
pma111Author Commented:
Is there anything I need to change in that ps1 or can it be run as is? I am new to powershell/scripting, but I get an error "unexpected token 'add-member' in expression or statement.
0
becraigCommented:
Can you paste the exact error output when run please.

Also can you give me the output from the following command:
$PSVersionTable.PSVersion
0
pma111Author Commented:
sorry for the late reply I have been off sick

re the version
major.minor.build.revision
2.0.-1.-1
0
pma111Author Commented:
unexpected token 'add-member' in expression or statement.

at <path> file.ps1:7 char:18

Open in new window

0
becraigCommented:
This should work for you:

$report = @()
gci C:\users\Administrator\Desktop | where {$_.Psiscontainer -eq $false} | % {
write-host "Processing $_.Fullname"
$hlink = '=HYPERLINK("'+$_.Fullname+'")'
$hashval = Get-FileHash $_.FullName | select -expa hash

    $item = New-Object PSObject -Property @{
    Name = $_.Name
    Fullname = $hlink
    CREATED = $_.CreationTime
    ACCESSED = $_.LastAccessTime
    MODIFIED = $_.LastWriteTime
    FILEHASH = $hashval          
    }
    $report += $item

}
$report | Export-Csv report.csv -nti
                                          

Open in new window

0
pma111Author Commented:
sorry not provided feedback will try this now
0
pma111Author Commented:
another error with the revised script

unexpected token 'add-member' in expression or statement.
at <removed> script.ps1:7 char:18
0
becraigCommented:
No clue why this is failing for you and with very little to go on I will just use a different approach:

$report = @()
$report += "Name`tFullname`tCREATED`tACCESSED`tMODIFIED`tFILEHASH"
gci C:\users\Administrator\Desktop\scripts | where {$_.Psiscontainer -eq $false} | % {
$fname=$_.name;$created = $_.CreationTime;$laccess = $_.LastAccessTime;$lwrite = $_.LastWriteTime
write-host "Processing $fname"
$hlink = '=HYPERLINK("'+$_.Fullname+'")'
$hashval = Get-FileHash $_.FullName | select -expa hash
$report += "$fname`t$hlink`t$created`t$laccess`t$lwrite`t$hashval"
}
$report | out-file report.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.