# Set all values of keys in pscustomobject to single value

**URL:** <https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704>\
**Category:** PowerShell Help\
**Created:** [June 1, 2021, 12:48pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704 "2021-06-01T12:48:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul20](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rahul20](https://forums.powershell.org/u/Rahul20)\
**Post date:** [June 1, 2021, 12:48pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/1 "2021-06-01T12:48:42Z")

</div>

hello there!

Can someone help me on below:

I am trying to assign all values of keys in PSCustomObject to “N/A”. Here’s what I was trying to do:

```auto
           $Object = [PSCustomObject]@{

            GivenName = $GivenName
            Surname = $Surname
            EmailAddress = $Surname
            Office = $Office
            Title = $Title

            }

```

Now, I need all the sub keys to be “NA”. How can I achieve this ?

Thanks.

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [June 1, 2021, 3:28pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/2 "2021-06-01T15:28:04Z")

</div>

`$Object.psobject.properties | ForEach-Object {$_.Value = 'N/A'}`

---

<div class="post-metadata">

**Author:** ![Rahul20](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rahul20](https://forums.powershell.org/u/Rahul20)\
**Post date:** [June 1, 2021, 5:52pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/3 "2021-06-01T17:52:02Z")

</div>

@matt-bloomfield , Hello Matt, Thanks for answering.

But, I am getting error when I run the command

$Object.psobject.properties : The term ‘$Object.psobject.properties’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that  
the path is correct and try again.

```auto
At line:1 char:5
+ $Object.psobject.properties | ForEach-Object {$_.Value = ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: ($Object.psobject.properties:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

```

can you please help, what went wrong?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 1, 2021, 6:36pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/4 "2021-06-01T18:36:18Z")

</div>

> [@Rahul20](#):
>
> But, I am getting error when I run the command

Really? I get exactly what you’ve asked for:

```auto
$Object = 
[PSCustomObject]@{
    GivenName = $GivenName
    Surname = $Surname
    EmailAddress = $Surname
    Office = $Office
    Title = $Title
}
$Object.psobject.properties | ForEach-Object { $_.Value = 'N/A' }

```

The ouput is:

```auto
GivenName : N/A
Surname : N/A
EmailAddress : N/A
Office : N/A
Title : N/A

```

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [June 1, 2021, 8:33pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/5 "2021-06-01T20:33:19Z")

</div>

I can’t replicate that error message. Even if the object is not created, you don’t get that error message.

---

<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:24pm UTC](https://forums.powershell.org/t/set-all-values-of-keys-in-pscustomobject-to-single-value/16704/6 "2024-05-16T20:24:20Z")

</div>

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


