How to test the word automation service
The word autmation service makes it possible to convert word documents into pdf document out of the box.
Sometimes it is helpful to test the autmation service. So here comes the power of the PowerShell:
$AppName="Word Automation Services" $timerJobName="Word Automation Services" $SiteUrl="http://portal.contoso.com" $WordDoc="/Freigegebene%20Dokumente/Fdsfsfd.docx" $PDF="/Freigegebene%20Dokumente/test.pdf"
asnp *sh* Write-Host -BackgroundColor Green -ForegroundColor Yellow " --- Test Word Automation Service --- " write-host "" $WASinstance=Get-SPServiceInstance | ?{$_.typename -eq "Word Automation Services"} IF ($WASinstance.Status -ne "Online") { Write-Host -ForegroundColor Red -BackgroundColor White " - Service Instance not started !! - Status: "$WASinstance.Status Write-Host " - Run to start: (Get-SPServiceInstance | ?{$_.typename -eq "Word Automation Services"}).Provision()" break }
Write-Host -BackgroundColor Green -ForegroundColor Yellow " --- Test Word Automation Service Application --- " write-host "" Write-Host "Check service application: "$AppName
$was=Get-SPServiceApplication -Name $AppName -ErrorAction SilentlyContinue if (!$was) { Write-Host -ForegroundColor Red -BackgroundColor White " - Service application not found !!" break } Write-Host -ForegroundColor Green " - Service application found" Write-Host -ForegroundColor Green " - Status : "$was.Status
Write-Host "Convert Word document to PDF : "$SiteUrl $WordDoc [void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.Office.Word.Server" ) $jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings $jobSettings.OutputFormat = "PDF" $job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob( $AppName, $jobSettings ) $job.UserToken = (Get-SPWeb $SiteUrl).CurrentUser.UserToken $job.AddFile($SiteUrl+$WordDoc,$SiteUrl+$PDF) $job.Name="TEST JOB !!!!!!!" $job.Start( )
Write-Host "" Write-Host "Starting Timer job : " $timerJobNameget-sps Start-SPTimerJob $timerJobName
Write-Host "Job status:" new-object Microsoft.Office.Word.Server.Conversions.ConversionJobStatus($AppName, $job.JobId,$null);
Write-Host "" Write-Host -ForegroundColor Green "--- Test done ---"
In the head you have the variables to declare the Word automation Service Name (not the proxy), the source location and the destination for the pdf file
With the following script you can list all jobs from the service to get the state of the job.
Function ListConversionsStatus { $AppName="Word Automation Services" [void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.Office.Word.Server" ) $WASAllJobs=[Microsoft.Office.Word.Server.Conversions.ConversionJobStatus]::GetAllJobs($AppName, $null) foreach ($WASJob in $WASAllJobs) { $WASJob new-object Microsoft.Office.Word.Server.Conversions.ConversionJobStatus($AppName, $WASJob.JobId,$null); } }
Write-Host "" Write-Host -ForegroundColor Green "List all conversion jobs : run command: ListConversionsStatus"
















