Guest User

msi-search&copy

a guest
Feb 6th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Sets source directory
  2. $outputPath = "C:\ProgramData\flx\Output"
  3.  
  4. #Sets destination directory
  5. $sharePath = "C:\Test-New"
  6.  
  7. #Sets current time
  8. $time=Get-Date
  9.  
  10. #Sets amount of time (in minutes) to go back
  11. $minutes=-15
  12.  
  13. #Variables for log file
  14. $logFile = Join-Path -path $sharePath -childpath "MSI_copy.log"
  15.  
  16. #Searches source directory for .msi
  17. $listofFiles=(Get-ChildItem -Recurse -Path $outputPath -Include "*.msi" -Exclude "*.Context.msi" | where {$_.LastAccessTime -gt $time.AddMinutes($minutes)})
  18.  
  19. foreach ($file in $listofFiles) #example of $file: C:\ProgramData\flx\Output\<APP-NAME>_<VERSION>_<TIME_STAMP>\<APP-NAME>_<VERSION>\MSI Package\<APP-NAME>_<VERSION>.msi
  20. {
  21.     #Set folder path based on path of source MSI
  22.     $x = $file -split("_")
  23.     $msiRootFolder = Split-Path -leaf $x[0] #example: <APP-NAME>
  24.  
  25.     $y = ($file -split ("\\"))
  26.     $msiFolder = $y[4] #example: <APP-NAME>_c-20121120_20130117T233911
  27.  
  28.     $msiPath = "$msiRootFolder\$msiFolder" #example: <APP-NAME>\<APP-NAME>_<TIME_STAMP>
  29.  
  30.     #Set destination path for MSI
  31.     $msiLocation = Join-Path -path $sharePath -childpath $msiPath #example: C:\Test-New\BDW7MISCLIENT\BDW7MISCLIENT_c-20121120_20130117T233911\
  32.  
  33.     #Set timestamp for log file
  34.     $logTime = Get-Date -format "MM/dd/yy HH:mm:ss"
  35.  
  36.     #Create a folder for MSI if one does not already exist
  37.     if (!(Test-Path $msiLocation))
  38.     {
  39.         [void](New-Item $msiLocation -itemType directory)
  40.     }
  41.  
  42.     #Copy MSI from source to destination in $sharePath
  43.     Copy-Item $file -destination $msiLocation -ErrorVariable "CopyError"
  44.  
  45.     #Create log file for Copy-Item
  46.     if ($CopyError){"$logTime ERROR copying $msiFolder: $CopyError" >> $logFile}
  47.     else{"$logTime Successfully copied: $msiFolder" >> $logFile}
  48. }
Advertisement
Add Comment
Please, Sign In to add comment