Background
There is a directory that is automatically populated with MSI files during the day. I plan to use the Task Scheduler to run the script shown below every 15 minutes. The script will search the directory and copy all the new MSIs created in the last 15 minutes to the network share.
In this folder C:\ProgramData\flx\Output\<APP-NAME>\_<TIME_STAMP>\<APP-NAME>\ there are two other folders: Repackaged and MSI Package . The Repackaged folder Repackaged not need to be Repackaged because it does not contain MSI. I also found that it needs to be excluded in some way to prevent this error:
Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. At line:14 char:32 +$listofFiles=(Get-ChildItem <<<< -Recurse -Path $outputPath -Include "*.msi" -Exclude "*.Context.msi" | where {$_.LastAccessTime -gt $time.AddMinutes($minutes)}) + CategoryInfo : ReadError: C:\ProgramData\...xcellence\Leg 1:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
Limitations
- I am stuck using Powershell v1.0
- I have no control over the directory structure in the source location
Updated:
- I do not know the name of the application or what will be the timestamp. This is something that I can not do.
Current plans
I read about using -Filter , and I know about filters similar to functions, but I could not figure out how to use them. My only thought at the moment would be to do something like:
$searchList=Get-ChildItem "all instances of the MSI Package folder" foreach($folder in $searchList){ $listofFiles=Get-ChildItem "search for *.msi" foreach($file in $listofFiles){"Logic to copy MSI from source to destination"} }
However ... I thought there might be a more efficient way to do this.
Questions
- How to limit the search depth of Get-ChildItem?
- How can I limit the search for Get-ChildItem to
C:\ProgramData\flx\Output\<APP-NAME>_<TIME_STAMP>\<APP-NAME>\MSI Package - How can I only search for folders that you accessed in the last 15 minutes? I do not want to waste time drilling into folders when I know that MSI is already copied.
Additional recommendations on how to make this script more efficient in general will also be greatly appreciated.
Script
My current script can be found here . I continued to receive: "Your message seems to contain code that was not correctly formatted as code," and after the fourth attempt I refused to reformat it.
source share