c# - How do I consume Get-Content in a PowerShell cmdlet? -
the question powershell 3.0
cmdlet
using c#
in .net framework 4.0
in visual studio 2010
.
we're writing powershell cmdlet needs input pipeline. like...
get-content .\somefile.bin -encoding byte | receive-bytes
the receive-bytes cmdlet needs work same way set-content works. like...
get-content .\somefile.bin -encoding byte | set-content otherfile.bin -encoding byte
we have tried next 3 options:
[system.management.automation.parameter(position = 1, mandatory = true, valuefrompipeline = true)] public byte input { private get; set; } public byte[] input { private get; set; } public system.io.binaryreader input { private get; set; }
but... byte, byte[], binaryreader result in same error.
+ get-content .\somefile.bin | receive-bytes + ~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidargument: [receive-bytes], parameterbindingexception + fullyqualifiederrorid : receive-bytes : input object cannot bound parameters command either because command not take pipeline input or input , properties not match of parameters take pipeline input.
we noticed error repeats several times, suggesting get-content sending several chunks of data. researched , found case ( http://brianreiter.org/2010/01/29/powershells-object-pipeline-corrupts-piped-binary-data/ ) puts no closer solving it.
so... question is: how setup system.management.automation.parameter take byte stream sent get-content?
update: answers below point using -encoding byte on get-content, , within receive-bytes using...
public iconvertible input { private get; set; }
iconvertible gets info in. in receive-bytes doesn't match source file select get-content.
so... how setup parameter alter iconvertible byte stream?
take @ this article.
near end, illustration 7 seems cover question.
c# visual-studio-2010 powershell
No comments:
Post a Comment