Powershell 正确关闭 Sharepoint 文档

Powershell to properly shut down a Sharepoint document

我正在尝试使用 PowerShell 关闭位于 SharePoint 网站上的 PowerPoint 演示文稿。

我已经使用了 process.killStop-Process 命令,但问题是文件没有正确关闭并且在 SharePoint 站点上乱七八糟。如果我删除它,它会回来。我知道这与短期锁定有关,但我想避免这种情况。如果我 AltF4 PowerPoint 演示文稿或 Esc 它,文件将处于稳定状态。

尝试在使用 Stop-Process:

终止进程之前优雅地保存并关闭 PowerPoint 演示文稿
# If there is a powerpoint application running
If(Get-Process | ?{$_.ProcessName -eq "POWERPNT"}){

    $pp = [Runtime.Interopservices.Marshal]::GetActiveObject('powerpoint.application')
    $pp.Presentations | % { 
        $_.Save()
        $_.Close() 
    }

    # Kill off all PowerPoint apps
    Get-Process | ?{$_.ProcessName -eq "POWERPNT"} | Stop-Process
}