# Passing a set of characters to a function as a string without quotes

**URL:** <https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643>\
**Category:** PowerShell Help\
**Created:** [June 2, 2014, 8:01am UTC](https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643 "2014-06-02T08:01:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adbertram](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/adbertram/32/193_2.png) [@adbertram](https://forums.powershell.org/u/adbertram)\
**Post date:** [June 2, 2014, 8:01am UTC](https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643/1 "2014-06-02T08:01:48Z")

</div>

I’m trying to create a dead simple function in my profile that I can simply type “log something I just did”. The log will be the function name and the “I just did” will be some note. I realize I can easily just wrap the “I just did” in quotes and make this work but I want something that I can extremely quick just jot down a note. I know myself. If I have to worry about putting quotes around the “I Just did” string, I’ll mentally resent it.

Anyone know of a way I can just type this line: log this is a note

…and pass “this is a note” as a string or another datatype that I can convert to a string that I can turn around and add to a text file? How would I tell Powershell to treat “this is a note” as a single parameter instead of 4 separate parameters?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [June 2, 2014, 9:03am UTC](https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643/2 "2014-06-02T09:03:08Z")

</div>

You can’t pass a string with spaces without quoting it, but you could define a parameter with the ValueFromRemainingArguments attribute set. You’d wind up with an array of strings passed to the function, which it could then join into a single string. Something like this:

```
function log
{
    [CmdletBinding()]
    param (
        [Parameter(ValueFromRemainingArguments = $true)]
        [string[]]
        $Text
    )

    $string = $Text -join ' '

    Write-Host "Logging: $string"
}

log Something I just did.
```

---

<div class="post-metadata">

**Author:** ![adbertram](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/adbertram/32/193_2.png) [@adbertram](https://forums.powershell.org/u/adbertram)\
**Post date:** [June 2, 2014, 9:07am UTC](https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643/3 "2014-06-02T09:07:43Z")

</div>

ValueFromRemainingArguments is exactly what I was looking for. Thanks!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/passing-a-set-of-characters-to-a-function-as-a-string-without-quotes/2643/4 "2024-05-16T20:52:01Z")

</div>

Closed on May 16, 2024, 8:52pm UTC


