0

I've added an image to a word document using powershell. How can I resize?

$Word = New-Object -ComObject Word.Application

$Word.Visible = $True

$Document = $Word.Documents.Add()

$Selection = $Word.Selection

$Selection.InlineShapes.AddPicture("$imagelocation")|Out-Null

$Selection.InlineShapes.Height = 50

$Selection.InlineShapes.Width = 50

But I get the following errors:

Exception setting "Height": 
"The property 'Height' cannot be found on this object. Verify that the property exists and can be set."

Exception setting "Width": 
"The property 'Width' cannot be found on this object. Verify that the property exists and can be set."
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Chris
  • 17
  • 5

1 Answers1

3

You're attempting to set the Height and Width on the collection that contains all inline shapes.

Use the specific InlineShape object returned by AddPicture() instead:

$newInlineShape = $Selection.InlineShapes.AddPicture("$imagelocation")
$newInlineShape.Height = 50
$newInlineShape.Width = 50
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206