Once you have the file list collected into an array, it can be passed as arguments to a command. For example:
$fileList = @() Get-ChildItem -path "some-path" | ForEach-Object { if ($_.Length -gt 10MB) { $fileList += $_.FullName } } # now execute an external command & zip.exe output.zip $fileList
A very nice bonus of using this method is that when $fileList is passed to the call operator, $fileList is expanded with spaces between items and quotes around the items that contain one or more spaces. For example, if $fileList contains two items
C:\Program Files\Paint\Paint.exe
D:\Temp\abc.txt
$fileList is going to be expanded as:
"C:\Program Files\Paint\Paint.exe" D:\Temp\abc.txt
The other options to use is Invoke-Expression cmdlet. However, it's notoriously difficult to build strings from an array to have quotes around the items that contain spaces.
No comments:
Post a Comment