Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 951463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:44:27+00:00 2026-05-15T23:44:27+00:00

In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an

  • 0

In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an advanced function and noticed that it performs differently than when supplied to a compiled cmdlet.

In reviewing this blog post from the PowerShell Team blog, it appears that the PowerShell engine should be evaluating the scriptblock if a scriptblock is not a valid input for the parameter. It seems that when calling the function with a scriptblock parameter, it attempts to convert a scriptblock to the parameters type directly, rather than evaluating the scriptblock based on the current object in the pipeline.

My intention is to duplicate behavior like:

Import-CSV somecsv.csv | get-wmiobject -class {$_.class} -Computer {$_.computer}

for advanced functions.

Example script:

$sb = {throw "If there was an error, the scriptblock was evaluated!"}

function test ()
{
  param (
    [Parameter()]
    [string]
    $ThisShouldBeEvaluatedForEachItem,
    [Parameter(ValueFromPipelineByPropertyName = $true)]
    [string]
    $FullName
 )  

 process 
 {  
  write-host $Fullname, $ThisShouldBeEvaluatedForEachItem
 }
} 
Get-ChildItem | test -ThisShouldBeEvaluatedForEachItem $sb

Is this the intended behavior or am I headed in the wrong direction?

Based on Keith’s response, I added ValueFromPipeline and ValueFromPipelineByPropertyName (in two separate tests) to the Parameter attribute for the ThisShouldBeEvaluatedForEachItem parameter. Doing that makes the example work, though it seems to defeat the stated purpose of scriptblock parameters from the Team Blog post.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:44:27+00:00Added an answer on May 15, 2026 at 11:44 pm

    If the parameter is ValueFromPipeline or ValueFromPipelineByPropertyName then PowerShell will evaluate the Scriptblock and try to coerce the result to the parameter type. We got this info from the PowerShell team a while back:

    ScriptBlock arguments are passed as is
    (as a ScriptBlock) when the parameter
    type is Object, ScriptBlock, or a type
    deriving from ScriptBlock, or
    collections of these types.

    We only invoke the ScriptBlock
    argument during parameter binding when
    there is pipeline input and there was
    no trivial way to bind the ScriptBlock
    directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to look into your .htaccess file. A misconfiguration… May 16, 2026 at 11:14 am
  • Editorial Team
    Editorial Team added an answer The last stand-alone version of the .NET SDK was 2.0.… May 16, 2026 at 11:14 am
  • Editorial Team
    Editorial Team added an answer I think what you are looking for is called a… May 16, 2026 at 11:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

While experimenting with this question on collections in Spring.NET , I discovered that Spring
After experimenting with an iterator block I noticed the generated IL code is not
I'm an amateur programmer that's experimenting using pthreads, to see to what extent a
Experimenting with Ruby's Benchmark module... >> Benchmark.bm(7) { |b| b.report('Report:') { s = ''
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
Experimenting using different approaches and reducing code maintenance I have ended up using reflection
experimenting with Visitor pattern and generic method I found a kind of discrepancy in
Experimenting with existential types. Seems to be a great way to get some type
been experimenting with unordered list UL and i have seem varios examples of using
While experimenting with pixel shaders in WPF I decided to draw some pixels onto

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.