• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

catch array from pipe

R
#1
hello,

i have a script to sign file. but it will only sign the last file passed
down. (ls *.ps1 | sign) ps didn't show any syntax error. could you help
point it out?


function global:sign {

param(
[Parameter(mandatory=$true,ValueFromPipeline=$true)][System.io.fileinfo[]]$fileList
);

foreach ( $file in $fileList ) {
set-authenticodesignature -filepath $file -certificate ( ls
cert:\CurrentUser\my -codesigning );
}

}
 
S
#2
I think this is a common trap (at least for me). You have to specify
in the function that the block of code is process part:

function global:sign {
param([Parameter(mandatory=$true,ValueFromPipeline=$true)]
[System.io.fileinfo[]]$fileList)
process {
foreach ( $file in $fileList ) {
set-authenticodesignature -filepath $file -certificate ( ls cert:
\CurrentUser\my -codesigning );
}
}
}

On Feb 23, 9:51 am, ryan <r...@newsgroup> wrote:

> hello,
>
> i have a script to sign file. but it will only sign the last file passed
> down. (ls *.ps1 | sign) ps didn't show any syntax error. could you help
> point it out?
>
> function global:sign {
>
>    param(
> [Parameter(mandatory=$true,ValueFromPipeline=$true)][System.io.fileinfo[]]$fileList
> );
>
>    foreach ( $file in $fileList ) {
>       set-authenticodesignature -filepath $file -certificate ( ls
> cert:\CurrentUser\my -codesigning );
>    }
>
> }
 
R
#3
thank you

On 02-23-2010 5:14 PM, stej wrote:

> I think this is a common trap (at least for me). You have to specify
> in the function that the block of code is process part:
>
> function global:sign {
> param([Parameter(mandatory=$true,ValueFromPipeline=$true)]
> [System.io.fileinfo[]]$fileList)
> process {
> foreach ( $file in $fileList ) {
> set-authenticodesignature -filepath $file -certificate ( ls cert:
> \CurrentUser\my -codesigning );
> }
> }
> }
>
> On Feb 23, 9:51 am, ryan<r...@newsgroup> wrote:

>> hello,
>>
>> i have a script to sign file. but it will only sign the last file passed
>> down. (ls *.ps1 | sign) ps didn't show any syntax error. could you help
>> point it out?
>>
>> function global:sign {
>>
>> param(
>> [Parameter(mandatory=$true,ValueFromPipeline=$true)][System.io.fileinfo[]]$fileList
>> );
>>
>> foreach ( $file in $fileList ) {
>> set-authenticodesignature -filepath $file -certificate ( ls
>> cert:\CurrentUser\my -codesigning );
>> }
>>
>> }
>