Wednesday, 9 November 2011

Open-WordDocument.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script opens a word document using PowerShell 
  4. .DESCRIPTION 
  5.     This script re-implments a simple MSDN script to open 
  6.     a word document using VBA. IT Pros using PowerShell 
  7.     might also make use of to create rich documents as 
  8.     output from a script. 
  9. .NOTES 
  10.     File Name  : Open-WordDocument.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/bb148369%28office.12%29.aspx 
  18. .EXAMPLE 
  19.     Running this sample opens the file c:\foo\doc1.docx in Word. The  
  20.     COM object referring to the document is returned for later use. 
  21.      
  22. #> 
  23.  
  24. # Create Word Object 
  25. $wrd = new-object -com word.application 
  26.  
  27. # Make Word Visible 
  28. $wrd.visible = $true 
  29.  
  30. # Open a document  
  31. $doc = $wrd.documents.open("C:\foo\doc1.docx"

No comments: