Author Posts

August 13, 2018 at 7:09 am

Successfully extract contents from word document, but how can we save this as CSV file – where all data extracted goes in one row in csv

$newdoc = $word.Documents.Add()
$doc.Range($startPosition, $endPosition).Copy()
$newdoc.Content.Paste()
Write-host $newdoc.Content.Text
$newdoc.SaveAs("D:\found111.doc")
$newdoc.Close()

Document content is like this, which we want to save as one row in sql server Description about the document :

SQL Server Versions:    
(a) SQL Server 2016 to be used for all upcoming projects;
(b) SQL Server 2016 Enterprise edition will be used on all servers
(c) Assumptions:
    (i) SQL Server will be installed on VM instances

August 13, 2018 at 2:40 pm

You'll need to parse the text into an object. Each property in the object becomes a column in the CSV. You can then pipe the objects to Export-CSV to create a CSV file.

You might play with ConvertFrom-String – it's able to take a "template" of what your data looks like, and then parse other data into objects based on the template. There are numerous tutorials, as well as the command help, on Convert-FromString.