Reputation: 113
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
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