user3190414
user3190414

Reputation: 113

How to kill word document from taskbar using powershell script

I am writing a script to close word document from taskbar using PowerShell script. I am able to unpin the document using:

Pin-Taskbar -Item  -Action <Pin|Unpin>

However I need to close the document not unpin it. Not sure how to find the specific document and close it.

Upvotes: 1

Views: 2300

Answers (1)

Richard
Richard

Reputation: 7000

This following will close all the Word documents within all the Word applications, asking them if they want to save the document before it is closed. Then all Word application processes are killed off.

$wd = [Runtime.Interopservices.Marshal]::GetActiveObject('Word.Application')
$wd.Documents | % { $_.Close() }
Get-Process | ?{$_.ProcessName -eq "WINWORD"} | Stop-Process

Upvotes: 1

Related Questions