I ran across this code in another post that almost does what I need, but can\'t figure out how to modify it to look for specific file types, i.e. *.bak, .txt, etc. I\'m
This worked after creating a config file to use the .NET 4.0 Framework:
try{
$path = "\\$Server\$($drive.replace(':','$'))"
foreach ($filepath in [System.IO.Directory]::EnumerateFiles($path,"*.bak","AllDirectories"))
{
$file = New-Object System.IO.FileInfo($filepath)
write-host $file
# insert file into database table
}
}
catch [UnauthorizedAccessException]
{
$exception = $_.Exception.Message #I don't need to write/insert exception
}