Powershell - Save extracted content from word document as CSV file

Welcome Forums General PowerShell Q&A Powershell - Save extracted content from word document as CSV file

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
4 months ago.

  • Author
    Posts
  • #108322

    Participant
    Points: 0
    Rank: Member

    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
  • #108376

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Powershell - Save extracted content from word document as CSV file’ is closed to new replies.