User_1403834 User_1403834 - 1 year ago 333
PowerShell Question

Powershell Function to get metadata recursively

I'm modifying some powershell code that I found that gets metadata from files recursively, but I'm having trouble accessing the folders within the folders. I get the metadata from the folders that are directly listed under \share, and not the folders and files under there. How can I modify this code to the the metadata from the files within the folders?

Also, I'm trying to get the metadata exported to a CSV, but I just get an empty file.

EDIT: I'm trying to get the data from .pst files. I also found the following line and wondering if I can add this in somehow:

dir \myserver\share -Recurse -Include *.pst | Select FullName

($folder = "\\myserver\share") #end param
function funLine($strIN)
$strLine = "=" * $strIn.length
$hash | Export-Csv c:\pstdetails.csv -NoClobber -NoTypeInformation
# Write-Host -ForegroundColor Yellow "`n$strIN"
# Write-Host -ForegroundColor Cyan $strLine
} #end funline
function funMetaData()
foreach($sFolder in $folder)
$a = 0
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($sFolder)
foreach ($strFileName in $objFolder.items())
{ FunLine( "$($")
for ($a ; $a -le 266; $a++)
if($objFolder.getDetailsOf($strFileName, $a))
$hash += @{ `
$($objFolder.getDetailsOf($objFolder.items, $a)) =`
$($objFolder.getDetailsOf($strFileName, $a))
} #end hash
} #end if
} #end for
} #end foreach
} #end foreach
} #end funMetadata

Answer Source

After searching high and low, the answer was in front of me all along. (I did search here previously!) Found the answer here: Recursive file search using powershell

I modified it to what columns I needed, so here's the code I used:

Get-ChildItem -Path \\Server\Folder -Filter *.pst -Recurse | Select-Object Directory, Name, Length, CreationTime, LastAccessTime, LastWriteTime | Export-Csv "c:\emails1.csv"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download