Set all values of keys in pscustomobject to single value

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:

           $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 ?


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


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

But, I am getting error when I run the command

$ : The term ‘$’ 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.

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

can you please help, what went wrong?

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

$Object = 
    GivenName    = $GivenName
    Surname      = $Surname
    EmailAddress = $Surname
    Office       = $Office
    Title        = $Title
$ | ForEach-Object { $_.Value = 'N/A' }

The ouput is:

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

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