15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1
theme-sticky-logo-alt

Test the Word Automation Service Application with PowerShell

2 Comments

The Word Automation Services Service Application is a Service Application that automatically converts documents supported by the Word client application into formats such as PDF and XPS. In a simpler way to explain it, the Word Automation Services takes the “Save As” functionality of the Word client, and replicates the functionality on SharePoint.

However, the Word Automation Service Application, does not have a user interface to test that it was configured properly. The only way to actually Test the Word Automation Service Application is trough code, which as a SharePoint IT Professional, I don’t want to write code simply to test a Service Application. Luckily, PowerShell is there for us! By using PowerShell, we can convert a document from Word to PDF, and test that this service application is working properly!

We will first load the assembly required to call Word Automation Services functions.

Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.Word.Server\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.Office.Word.Server.dll'

We then create new Object of type ConversionJobSettings specifying the Output format is PDF.

$jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings
$jobSettings.OutputFormat = "PDF"

We then create a new object of type ConversionJob and give it our Service Application Proxy Name, in our case Word Automation, as well as the $jobsettings object. We then set the $Job.Usertoken to the SharePoint SPWeb where the document is stored.

 

$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob("Word Automation", $jobSettings)
$job.UserToken = (Get-SPWeb https://sharepoint.learn-sp2016.com).CurrentUser.UserToken

Lastly, we add the properties for the file that we want converted. We give it the URL to the Word Document, as well as the URL to the future PDF document, which does not exist yet. We then Start the Job.

$job.AddFile("https://sharepoint.learn-sp2016.com/Shared%20Documents/Document1.docx", "https://sharepoint.learn-sp2016.com/Shared%20Documents/Document1-Final.pdf")
$job.Start()

The Word Automation Services job runs asynchronous, meaning that we won’t know when it will run directly from PowerShell, however we can force the job to run right away by starting the Word Automation timer job.

Start-SPTimerJob "Word Automation"

If we put it all together, the script looks like this:

 

Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.Word.Server\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.Office.Word.Server.dll'
$jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings
$jobSettings.OutputFormat = "PDF"
$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob("Word Automation", $jobSettings)
$job.UserToken = (Get-SPWeb https://sharepoint.learn-sp2016.com).CurrentUser.UserToken
$job.AddFile("https://sharepoint.learn-sp2016.com/Shared%20Documents/Document1.docx", "https://sharepoint.learn-sp2016.com/Shared%20Documents/Document1-Final.pdf")
$job.Start()
Start-SPTimerJob "Word Automation"

To see the status of the job, run the following PowerShell cmdlet where “Word Automation” is the name of your Word Automation Services Application.

new-object Microsoft.Office.Word.Server.Conversions.ConversionJobStatus("Word Automation", $job.JobId,$null);

Initially it will show as InProgress since we force started the Timer Job as seen in the screenshot below.

Test the Word Automation Service Application

Once the job is completed, it will either show as Succeeded or Failed. If everything was configured correctly, it should show as Succeeded as seen in the screenshot below, and you should see your PDF document in your document library.

Test the Word Automation Service Application

Did you find this article useful?

If yes, you will love Deploying SharePoint 2016: Best Practices for Installing, Configuring, and Maintaining SharePoint Server 2016 written by myself, and SharePoint Server MVP Trevor Seward! Get it now at the links below!

Follow me on Social Media and Share this article with your friends!


Leave a comment and don’t forget to like the Absolute SharePoint Blog Page   on Facebook and to follow me on Twitter here  for the latest news and technical articles on SharePoint.  I am also a Pluralsight author, and you can view all the courses I created on my author page.
Previous Post
My Conferences for the rest of 2016
Next Post
New Pluralsight Course: Planning for SharePoint Server 2016: Physical Topology and Services

2 Comments

  • April 4, 2017 at 4:22 pm
    Jen Hays

    If you are using a websvcapps account for the Word Automation Service, does that need access in SQL to the Content DBs?

    Reply
  • April 4, 2017 at 4:23 pm
    Jen Hays

    Forgot to mention, Deploying SharePoint 2016 is a great resource!

    Reply

Leave a Reply