2

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( "$($strFileName.name)")
     for ($a ; $a  -le 266; $a++)
      { 
       if($objFolder.getDetailsOf($strFileName, $a))
        {
         $hash += @{ `
              $($objFolder.getDetailsOf($objFolder.items, $a))  =`
              $($objFolder.getDetailsOf($strFileName, $a)) 
         } #end hash
         $hash
         $hash.clear()
          } #end if
      } #end for 
    $a=0
   } #end foreach
 } #end foreach
} #end funMetadata 
User_1403834
  • 411
  • 2
  • 7
  • 20

1 Answers1

0

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"
Community
  • 1
  • 1
User_1403834
  • 411
  • 2
  • 7
  • 20