Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Save unsaved files

$
0
0

I need to save all open Excel, Word, and PowerPoint documents to a temp directory(C:\temp\), regardless if they have ever been saved or not.  The saved file will be the "CurrentDocumentTitle + Timestamp".Extension.  I can use WASP to pull all open workbooks/documents in Excel, Word, and PowerPoint.  I can get A file to save, but it contains no content (at least unreadable).  I cannot seem to get this to work correctly, and I'm really hoping that this can be accomplished using PowerShell.  The intent of this is to be able to run an Acrobat uninstaller across multiple systems in my domain using SCCM.  I'm asking the users to save their work and close their applications so the uninstaller can run, unfortunately, they are not acting accordingly.  Any help would greatly be appreciated.

Set-ExecutionPolicy unrestricted -force
import-module C:\temp\WASP\WASP.dll -force #location of WASP

Function logstamp {
    $now=get-Date
    $yr = $now.Year.ToString()
    $mo = $now.Month.ToString()
    $dy = $now.Day.ToString()
    $hr = $now.Hour.ToString()
    $mi = $now.Minute.ToString()
    $se = $now.Second.ToString()
    if ($mo.length -lt 2) {
        $mo = "0" + $mo
    }
    if ($dy.length -lt 2) {
        $dy = "0" + $dy
    }
    if ($hr.length -lt 2) {
        $hr = "0" + $hr
    }
    if ($mi.length -lt 2) {
        $mi = "0" + $mi
    }
    if ($se.length -lt 2) {
        $se = "0" + $se
    }
    write-output $yr$mo$dy$hr$mi$se
}
$logstamp = logstamp

$filepath = "C:\temp\"
$objects = Select-Window | Where-Object {$_.Title -like "*Excel" -or $_.Title -like "*Word" -or $_.Title -like "*PowerPoint"} #SEARCHES FOR ALL OPEN WINDOWS OF LISTED TYPES (SAVED OR UNSAVED)
foreach($file in $objects){
    If ($file.Title -like "*Excel"){ #Set extension for Excel
        $ext = ".xlsx"
        #$a = New-Object -comobject Excel.Application
        #$a.Visible = $true
        #$book = $a.Workbooks.open($file)
        #$book.Save($filepath + $file.Title + $logstamp + $ext)
        #$a.Quit()
    }
    Elseif ($file.Title -like "*Word"){ #Set extension for Word
        $ext = ".docx"
    }
    Elseif ($file.Title -like "*PowerPoint"){ #Set extension for PowerPoint
        $ext = ".pptx"
    }
    $ofile = out-file ($filepath + $file.Title + $logstamp + $ext)
}
$ofile


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>