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
         }
   }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s