Working with Google Contacts as CSV and looking to ensure that the e-mail value is lower case, the default name for the e-mail address column is "E-Mail 1 - Value" and so looking to iterate only that column. However, the punctuation is causing a problem:
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $csv | Get-Member -MemberType Properties
TypeName: CSV:System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Additional Name NoteProperty string Additional Name=
Additional Name Yomi NoteProperty string Additional Name Yomi=
Billing Information NoteProperty string Billing Information=
Birthday NoteProperty string Birthday=
Directory Server NoteProperty string Directory Server=
E-mail 1 - Type NoteProperty string E-mail 1 - Type=
E-mail 1 - Value NoteProperty string E-mail 1 - Value=Conwayfp@Shaw.Ca
Family Name NoteProperty string Family Name=Pauls
Family Name Yomi NoteProperty string Family Name Yomi=
Gender NoteProperty string Gender=
Given Name NoteProperty string Given Name=
Given Name Yomi NoteProperty string Given Name Yomi=
Group Membership NoteProperty string Group Membership=
Hobby NoteProperty string Hobby=
Initials NoteProperty string Initials=
Language NoteProperty string Language=
Location NoteProperty string Location=
Maiden Name NoteProperty string Maiden Name=
Mileage NoteProperty string Mileage=
Name NoteProperty string Name=Conway
Name Prefix NoteProperty string Name Prefix=
Name Suffix NoteProperty string Name Suffix=
Nickname NoteProperty string Nickname=
Notes NoteProperty string Notes=
Occupation NoteProperty string Occupation=
Phone 1 - Type NoteProperty string Phone 1 - Type=Mobile
Phone 1 - Value NoteProperty string Phone 1 - Value=2502034036
Phone 2 - Type NoteProperty string Phone 2 - Type=
Phone 2 - Value NoteProperty string Phone 2 - Value=
Photo NoteProperty string Photo=
Priority NoteProperty string Priority=
Sensitivity NoteProperty string Sensitivity=
Short Name NoteProperty string Short Name=
Subject NoteProperty string Subject=
Yomi Name NoteProperty string Yomi Name=
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $csv | ForEach-Object {$_.'E-mail 1 - Value'.(Get-Culture).TextInfo.ToLower($_.'E-mail 1 - Value') }
which is returning an error of:
At line:1 char:24
+ ... ach-Object {$_.'E-mail 1 - Value'.(Get-Culture).TextInfo.ToLower($_.' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:1 char:24
+ ... ach-Object {$_.'E-mail 1 - Value'.(Get-Culture).TextInfo.ToLower($_.' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:1 char:24
PS C:\Users\Nick\Desktop>
which I take to mean that the column isn't being referenced correctly. In short, how are spaces escaped in this situation?
see also:
How to convert a specific CSV column to TitleCase with PowerShell from the REPL console?