0

Context is this previous linked question.

Where I seem to be stuck is on how to pipe using the ForEach-Object function as below:

PS C:\Users\Nick\Documents>
PS C:\Users\Nick\Documents> $TextInfo = (New-Object System.Globalization.CultureInfo("en-US")).TextInfo;
PS C:\Users\Nick\Documents>
PS C:\Users\Nick\Documents> $TextInfo


ANSICodePage   : 1252
OEMCodePage    : 437
MacCodePage    : 10000
EBCDICCodePage : 37
LCID           : 1033
CultureName    : en-US
IsReadOnly     : False
ListSeparator  : ,
IsRightToLeft  : False



PS C:\Users\Nick\Documents>
PS C:\Users\Nick\Documents>
PS C:\Users\Nick\Documents> $csv = Import-Csv -Path .\abcd.csv |
>>  ForEach-Object {
>> $_.Name = $TextInfo.toTitleCase($_.Name)
>> $_
>> }
Exception setting "Name": "The property 'Name' cannot be found on this object. Verify that the property exists and can
be set."
At line:3 char:1
+ $_.Name = $TextInfo.toTitleCase($_.Name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting "Name": "The property 'Name' cannot be found on this object. Verify that the property exists and can
be set."
At line:3 char:1
+ $_.Name = $TextInfo.toTitleCase($_.Name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting "Name": "The property 'Name' cannot be found on this object. Verify that the property exists and can
be set."
At line:3 char:1
+ $_.Name = $TextInfo.toTitleCase($_.Name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting "Name": "The property 'Name' cannot be found on this object. Verify that the property exists and can
be set."
At line:3 char:1
+ $_.Name = $TextInfo.toTitleCase($_.Name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting "Name": "The property 'Name' cannot be found on this object. Verify that the property exists and can
be set."
At line:3 char:1
+ $_.Name = $TextInfo.toTitleCase($_.Name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

PS C:\Users\Nick\Documents>
PS C:\Users\Nick\Documents> $csv

alpha       beta       charlie    delta
-----       ----       -------    -----
sdkljgsdf   bdgfhgfnhm ngfgfddfsg dfhgsdfg
gfjd;saklbf dfbdfgfn   vfsdafdfbn fgjtyj
bdgfkl;     dsfsd      vgngfas    dsfhgtj
dsbmnkl     nggfn      bfdsda     edtshdgf
asdfkl      sdagfdfh   vbdfdngt   ngfggj


PS C:\Users\Nick\Documents>

mostly using Linux, which I think is PS Core. Above, this is on Windows.

I tried the above code on Windows. Looking to use the REPL console.

This is a follow up to a question which I cannot edit at the moment.

Mostly, just an iteration problem with the console usage. By REPL I mean the console on the command line -- either bash or the windows CMD.

  • 1
    Your CSV doesnt have a `Name` column so `$_.Name` fails. Are you looking to `ToTitleCase` all property values of your objects? – Santiago Squarzon Jun 13 '23 at 19:30
  • ah, thanks. yes, just run on everything pls. is it a problem to do from the console? – Nicholas Saunders Jun 13 '23 at 19:38
  • 1
    the previous answer in your question is already showing you how to do that: is that not working? if so, edit your question explaining what is the issue you have while using that code – Santiago Squarzon Jun 13 '23 at 19:42
  • I can't edit that question at the moment, but no it's not working from the console for me. – Nicholas Saunders Jun 13 '23 at 19:52
  • Please provide feedback on the answers that were given to your previous question instead of asking essentially the same question again. As in your previous question, your sample CSV shows that there is no `Name` column; here, you have columns named `alpha`, `beta`, ..., so you must target one of those, as discussed in the context of the linked post, where there's also a solution to target _all_ columns (properties). – mklement0 Jun 13 '23 at 19:59
  • I wasn't able to comment earlier, but have now updated the original question. Pardon any confusion. – Nicholas Saunders Jun 14 '23 at 15:40

0 Answers0