Expand-Archive -PassThru incorrect work

Topics: Developer Forum
Nov 12, 2014 at 2:35 PM
Edited Nov 12, 2014 at 2:36 PM
Hi,

In 3.2 release where is incorrect work of -PassThru parameter in Expand-Archive cmdlet.

First Example:
$zipFile = c:\Temp\example.zip
Expand-Archive $zipFile -PassThru |  gm
TypeName: System.IO.FileInfo

Expand-Archive $zipFile -PassThru |  %{ Write-Output $_.Name }
example.zip
Second example:
$zipFile = c:\Temp\example.zip
Read-Archive $zipFile | where Name -match \.xlsx | Expand-Archive -PassThru |  gm
TypeName: Pscx.Commands.IO.Compression.ArchiveReader.ArchiveEntry

Read-Archive $zipFile | where Name -match \.xlsx | Expand-Archive -PassThru |   Write-Output 
   Zip Folder: example.zip#\
Index          LastWriteTime              Size        Name              CRC                                                                                       
-----          -------------                    ----        ----                  ---                                                                                       
12             2014-11-11    18:50        64512    example.xlsx   c2be59b0 
it means that original INPUT of the cmdlet is piped to pipeline.
Coordinator
Nov 18, 2014 at 4:19 AM
Yes. That is the behavior. I'm not sure what the question/issue is. The typical behavior of -PassThru is to pass through the object presented as input to the command.
Nov 19, 2014 at 9:12 AM
r_keith_hill wrote:
The typical behavior of -PassThru is to pass through the object presented as input to the command.
lol. The tipical behavior of -PassThru is to pass the OUTPUT of the command if it needed.

lets take a short look:

gcm -CommandType 8 | ? {$_.definition -match 'passthru'}

in this set we see lot of commands that are "similar" to the Exapnd-Archive:
Copy-Item
Reaname-Item
Move-Item
.... and so on

All of this cmdlets get some input from pipiline, make some works and by defauli not pipe anything to pipeline.
But if you use -PassThru - all of this cmdlets pipe to pipeline object(s) that represents result of it's work.
Copy-Item and Move-Item pipe FileInfo of new location.
Rename-Item - pipe new name...

More about -PassThru you can find in this article:
http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/18/use-the-powershell-passthru-parameter-and-get-back-objects.aspx
heyscriptingguy wrote:
Well, ML, as you can see, using the passthru parameter forces Windows PowerShell to go ahead and pass newly created or modified objects instead of hiding them.
And another thing.
In PowerShell 5.0 Technical Preview (Win Management Framework 5.0) whera are new namespace preseneted:
Microsoft.PowerShell.Archive

and here we can find 2 cmdlets: Expand-Archive and Compress-Archive

in documentation for the Expand-Archive we can find following:

Outputs
The output type is the type of the objects that the cmdlet emits.
System.IO.FileInfo or System.IO.DirectoryInfo

for today this feature dosn't work. :( but in documentation it's anounced.


BTW. If you try to start Get-Help Expand-Archive -full you can see the following:

-PassThru <SwitchParameter>
Output a FileInfo or DirectoryInfo for each file or directory expanded, respectively.
If -Passthru is specified, one ore more FileSystemInfo object(s) (FileInfo/DirectoryInfo) may be returned.
Coordinator
Nov 19, 2014 at 4:56 PM
OK I see what you are getting at. Would you mind submitting an issue and I'll try to get this out in 3.2.1 release.
Nov 19, 2014 at 9:17 PM
r_keith_hill wrote:
OK I see what you are getting at. Would you mind submitting an issue and I'll try to get this out in 3.2.1 release.
done!