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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:17:56+00:00 2026-06-02T19:17:56+00:00

a simple example and i don’t know how to get it to work… function

  • 0

a simple example and i don’t know how to get it to work…

 function replace($rep, $by){ 
    Process { $_ -replace $rep, $by }
}

when I do

"test" | replace("test", "foo")

the result is

test

When I do

 function replace(){ 
    Process { $_ -replace "test", "foo" }
}

"test" | replace()

the result is

foo

any idea ?

  • 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-06-02T19:17:59+00:00Added an answer on June 2, 2026 at 7:17 pm

    Functions in PowerShell follow the same argument rules as cmdlets and native commands, that is, arguments are separated by spaces (and yes, this also means you don’t need to quote your arguments, as they are automatically interpreted as strings in that parsing mode):

    'test' | replace test foo
    

    So if you call a PowerShell function or cmdlet with arguments in parentheses you’ll get a single argument that is an array within the function. Invocations of methods on objects follow other rules (that look roughly like in C#).

    To elaborate a little: PowerShell has two different modes in which it parses a line: expression mode and command mode. In expression mode PowerShell behaves like a REPL. You can type 1+1 and get 2 back, or type 'foo' -replace 'o' and get f back. Command mode is for mimicking a shell’s behaviour. That’s when you want to run command, e.g. Get-ChildItem or & 'C:\Program Files\Foo\foo.exe' bar blah. Within parentheses mode determination starts anew which is why Write-Host (Get-ChildItem) is different from Write-Host Get-ChildItem.

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

Sidebar

Related Questions

I don't know if it is possible, but there is simple example what I
I am teaching myself C# (I don't know much yet). In this simple example:
I don't know if I worded it correctly, but for a simple example let's
Have a look a this simple example. I don't quite understand why o1 prints
i want a simple example of if clause in mysql. i don't want to
i have this simple example here : http://jsfiddle.net/pTyvc/1/ i don't want the sub_menu div
Can some one give me a simple example of Raphael eve() ? I don't
I made this simple example , which doesn't work in Chrome 16 (latest), but
I have a simple example of what I don't understand about memory management on
I'd like a simple example of exporting a function from a C++ Windows DLL.

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.