Function to keep PSTools up to date

function Get-SysInternals {
 
  $sysIntDir="c:PSTools"
  
   if( !$sysIntDir.endsWith("")) { $sysIntDir+="" }
   $log = Join-Path $sysIntDir "changes.log"
   add-content -force $log -value "`n`n[$(get-date)]SysInternals sync has started"
      dir \live.sysinternals.comtools -recurse | foreach {
 
         $fileName = $_.name
         $localFile = join-path $sysIntDir $_.name                 
         $exist = test-path $localFile
        
         $msgNew = "new utility found: $fileName , downloading…"
         $msgUpdate = "file : $fileName  is newer, updating…"
         $msgNoChange = "nothing changed for: $fileName"
        
 
         if($exist){
            if($_.lastWriteTime -gt (get-item $localFile).lastWriteTime){
               Copy-Item $_.fullname $sysIntDir -force
               Write-Host $msgUpdate -fore yellow
               Add-Content -force $log -value $msgUpdate
            } else {
               Add-Content $log -force -value $msgNoChange
               Write-Host $msgNoChange
            }
          } else {
               if($_.extension -eq ".exe") {
                  write-host $msgNew -fore green
                  add-content -force $log -value $msgNew
               }
               Copy-Item $_.fullname $sysIntDir -force
         }
   }
}

Excel ‘sheetToCopy’

Whenever I see a post from Kiron
I know it will be good.

This copies the ‘sheetToCopy’ sheet from a source workbook (Book1.xlsx) to a destination workbook (Book2.xlsx).

I’ve commented the steps but if you’d like a better description of the process let me know and I’ll try my best…

$file1 = ‘C:Book1.xlsx’                            # source’s fullpath

$file2 = ‘C:Book2.xlsx’                       # destination’s fullpath

$xl = new-object -c excel.application

$xl.displayAlerts = $false                      # don’t prompt the user

$wb1 = $xl.workbooks.open($file1, $null, $true) # open source, readonly

$wb2 = $xl.workbooks.open($file2)                         # open target

$sh1_wb2 = $wb2.sheets.item(1)    # first sheet in destination workbook

$sheetToCopy = $wb1.sheets.item(‘sheetToCopy’)   # source sheet to copy

$sheetToCopy.copy($sh1_wb2) # copy source sheet to destination workbook

$wb1.close($false)                   # close source workbook w/o saving

$wb2.close($true)                 # close and save destination workbook

$xl.quit()

spps -n excel


Kiron