Hey Folks,
I’ve been looking into a problem of a friend of mine. He has a group people filling aut a form (word / doc /docx ) and these are in a folder. So we need to automate the processing hundreds documents and grab specific parameters and write the into a “.csv”-file.
So, I can read the files and stack them but fishing the specified string, that`s where it starts to get tuff.
Can anybody help out here?
$docPath = $args[0] Write-Host "Processing Documents from:" $docPath $all_docs = Get-ChildItem $docPath -filter "*.docx" $word = New-Object -comobject "Word.Application" $word.Visible = $False # Now, open each document and list the "ContentControls" $all_items = @() foreach ( $doc in $all_docs) { Write-Host "Processing :" $doc.FullName $doc = $word.Documents.Open($doc.FullName); $controls = $doc.ContentControls.Count Write-Host "Found : " $controls.Count " Content Controls" # Now, we create a collection of custom objects which are holding the data $item = New-Object System.Object foreach ( $control in $doc.ContentControls ) { $item | Add-Member -type NoteProperty -name $control.Title -value $control.Range.Text } $item $all_items += $item $doc.Close() } # Last, we save the collection to a CSV file $all_items | Export-CSV "exportData_DATE.CSV"