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 7088505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:48:33+00:00 2026-05-28T07:48:33+00:00

The following powershell script one,two,three | % { $(($l++)): $_ } will print 1:

  • 0

The following powershell script

"one","two","three" | % { "$(($l++)): $_" }

will print

1: one
2: two
3: three

However, after remove the bracket around $l++

"one","two","three" | % { "$($l++): $_" }

it will print

: one
: two
: three
  • 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-28T07:48:33+00:00Added an answer on May 28, 2026 at 7:48 am

    This is because $l++ is a voidable statement. In powershell certain types of
    expressions, when used as statements, are not displayed.
    Voidable statements include assignments and the increment/decrement operators. When they are used in an expression, they return a value, but when they’re used as a standalone statement, they return no value. It is very well explained in Windows Powershell in Action by Bruce Payette:

    The increment and decrement operators were almost not included in PowerShell
    because they introduced a problem. In languages such as C and C#, when you use
    one of these operators as a statement:
    $a++
    nothing is displayed. This is because statements in C and C# don’t return values. In
    PowerShell, however, all statements return a value. This led to confusion. People
    would write scripts like this:

    $sum=0
    $i=0
    while ($i -lt 10) { $sum += $i; $i++ }
    $sum
    

    and be surprised to see the numbers 1 through 10 displayed. This was because $a++
    returned a value and PowerShell was displaying the results of every statement. This
    was so confusing that we almost removed these operators from the language. Then we
    hit on the idea of a voidable statement. Basically, this means that certain types of
    expressions, when used as statements, are not displayed. Voidable statements include
    assignments and the increment/decrement operators. When they are used in an
    expression, they return a value, but when they’re used as a standalone statement, they
    return no value. Again, this is one of those details that won’t affect how you use PowerShell other than to make it work as you expect. (source: Windows Powershell in Action)

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

Sidebar

Related Questions

I'm trying to write a PowerShell script that will do the following: Executes a
I have the following string expression in a PowerShell script: select count(*) cnt from
Consider the following PowerShell script: function Alpha { # write-output 'Uncomment this line and
The following PowerShell script works if the resources are not there. Copy-Item $src_dir $dst_dir$agent_folder
I have the following snippet of PowerShell script in my profile: . (join-path (split-path
I am using Azure Management Cmdlets version 1.0. I run the following PowerShell script
I'm trying to write a PowerShell script that will automate my IIS website deployments.
I have the following powershell script which loads a custom .NET DLL this contains
Background: Assume I use the following powershell script from my local machine to automatically
I have two questions here, why does the following function in a script not

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.