Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Sets source directory
- $outputPath = "C:\ProgramData\flx\Output"
- #Sets destination directory
- $sharePath = "C:\Test-New"
- #Sets current time
- $time=Get-Date
- #Sets amount of time (in minutes) to go back
- $minutes=-15
- #Variables for log file
- $logFile = Join-Path -path $sharePath -childpath "MSI_copy.log"
- #Searches source directory for .msi
- $listofFiles=(Get-ChildItem -Recurse -Path $outputPath -Include "*.msi" -Exclude "*.Context.msi" | where {$_.LastAccessTime -gt $time.AddMinutes($minutes)})
- 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
- {
- #Set folder path based on path of source MSI
- $x = $file -split("_")
- $msiRootFolder = Split-Path -leaf $x[0] #example: <APP-NAME>
- $y = ($file -split ("\\"))
- $msiFolder = $y[4] #example: <APP-NAME>_c-20121120_20130117T233911
- $msiPath = "$msiRootFolder\$msiFolder" #example: <APP-NAME>\<APP-NAME>_<TIME_STAMP>
- #Set destination path for MSI
- $msiLocation = Join-Path -path $sharePath -childpath $msiPath #example: C:\Test-New\BDW7MISCLIENT\BDW7MISCLIENT_c-20121120_20130117T233911\
- #Set timestamp for log file
- $logTime = Get-Date -format "MM/dd/yy HH:mm:ss"
- #Create a folder for MSI if one does not already exist
- if (!(Test-Path $msiLocation))
- {
- [void](New-Item $msiLocation -itemType directory)
- }
- #Copy MSI from source to destination in $sharePath
- Copy-Item $file -destination $msiLocation -ErrorVariable "CopyError"
- #Create log file for Copy-Item
- if ($CopyError){"$logTime ERROR copying $msiFolder: $CopyError" >> $logFile}
- else{"$logTime Successfully copied: $msiFolder" >> $logFile}
- }
Advertisement
Add Comment
Please, Sign In to add comment