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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:25:21+00:00 2026-05-14T23:25:21+00:00

This is a very simple task in every language I have ever used, but

  • 0

This is a very simple task in every language I have ever used, but I can’t seem to figure it out in PowerShell. An example of what I’m talking about in C:

abs(x + y)

The expression x + y is evaluated, and the result passed to abs as the parameter… how do I do that in PowerShell? The only way I have figured out so far is to create a temporary variable to store the result of the expression, and pass that.

PowerShell seems to have very strange grammar and parsing rules that are constantly catching me by surprise, just like this situation. Does anyone know of documentation or a tutorial that explains the basic underlying theory of the language? I can’t believe these are all special cases, there must be some rhyme or reason that no tutorial I have yet read explains. And yes, I’ve read this question, and all of those tutorials are awful. I’ve pretty much been relegated to learning from existing code.

  • 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-14T23:25:21+00:00Added an answer on May 14, 2026 at 11:25 pm

    In your case, simply surrounding the expression with parenthesis will allow you to pass it to your function.


    You need to do this because PowerShell has more than one parsing mode depending on the beginning of the command.

    Expression mode is similar to how most other languages parse – numbers are numbers and strings are quoted.

    Command mode treats everything as a string except for variables and parenthesis. Strings here don’t need to be quoted.

    1+2          Expression mode - starts with number
    "string"     Expression mode - starts with quote
    string       Command mode - starts with letter
    & "string"   Command mode - starts with &
    . "string"   Command mode - starts with . and a space
    .123         Expression mode - starts with . and number (without space)
    .string      Command mode - starts with a . that is part of a command name
    

    You can mix modes in a single line by enclosing the commands with parenthesis.

    You can see this effect if you define function abs in the following way:

    function Abs($value)
    {
        Write-Host $args
        if($value -lt 0) { -$value } else { $value }
    }
    
    Abs 1 + 2
    #Prints:  + 2
    #Returns: 1
    
    Abs 1+2
    #Prints:  
    #Returns: 1+2
    
    Abs (1 + 2)
    #Prints:  
    #Returns: 3
    
    Abs (1+2)
    #Prints:  
    #Returns: 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be a very simple question, but I don't seem to be able
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
This is a very simple question with a simple answer, but it is not
I am sure this is a very simple problem, but I am new to
This may be a very simple problem, but I couldn't find an answer googleing
I have very simple select like this: SELECT * FROM table WHERE column1 IN
This very simple code gives me tons of errors: #include <iostream> #include <string> int
I've written this very simple function to replace a file extension using LINQ in
i am trying to compile this very simple piece of code class myList {
This seems like a very simple and a very common problem. The simplest example

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.