How to Find the Documents files which has a embedded object inside it ?

Mudit Mehrotra 1 Reputation point
2022-08-04T11:21:46.647+00:00

I have a folder with thousands of .docx files ,but there are some files which have other doc, excel ,ppt files attached inside as embedded objects.
I am using Powershell scripts to get the names of files which have embedded objects, but my script is not able to detect.
My script:

$path='F:\FinalTest\TestData_doc'
$types = '.docx','.doc'
$Files= Get-ChildItem -Path $path -recurse -Include $types
$Word = New-Object -ComObject Word.Application
Foreach ($File in $Files){
$Doc = $Word.Documents.Open($File.FullName,$null, $null, $null, "")
Write-Host $Doc.name"->"$Doc.inlineshapes
$Doc.Close([Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges)
}

Is there any other function or property that i can use to detect which files have attachments inside them(embedded objects) ?

Microsoft 365 and Office | Word | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,926 Reputation points
    2022-08-05T15:50:47.547+00:00

    Hi there,

    This might be the right place to look to get the script of your requirements.

    Understand Embedded Objects in PowerShell https://devblogs.microsoft.com/scripting/understand-embedded-objects-in-powershell/

    Use an Easy PowerShell Command to Search Files for Information https://devblogs.microsoft.com/scripting/use-an-easy-powershell-command-to-search-files-for-information/

    Weekend Scripter: Use PowerShell to Work with Embedded Objects https://devblogs.microsoft.com/scripting/weekend-scripter-use-powershell-to-work-with-embedded-objects/

    --------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–


  2. Mudit Mehrotra 1 Reputation point
    2022-08-08T10:53:22.377+00:00

    Hi @Limitless Technology , I am not unable to understand the scripting in that forum ,my requirement is to get names of the files which have embedded objects within itself .

    I got a result by searching :https://social.msdn.microsoft.com/Forums/en-US/8c790587-5384-4d8a-bc85-d3afa785145f/extract-all-types-of-embedded-and-attachment-files-from-word-document?forum=vsto

    but I can't able to convert the code into PowerShell. Can you help me to understand the code mentioned in the above link.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.