none
Get the columns name of a Sharepoint list when the columns name has spaces in it. RRS feed

  • Question

  • I have code that gets all the items of a SP list and export it to CSV. In the code below I have specify the column called "00:00 - 07:59". But it doesn't work because the columns name got spaces in it. I could use the InternalName but I don't want that. Is it possible to get the name of a column that has spaces in it?

    $ExportItem | Add-Member -MemberType NoteProperty -name "00:00 - 07:59" -value $_["00:00 - 07:59"]

    Gr, Peter

    • Moved by Bill_Stewart Friday, March 15, 2019 6:21 PM This is not "scripts on demand"
    Wednesday, January 23, 2019 7:25 AM

All replies

  • You can't use the previous pipeline inside a pipeline.  You are calling Add-Member in a new pipeline.

    $ExportItem | Add-Member -MemberType NoteProperty -name '00:00 - 07:59' -value $ExportItem['00:00 - 07:59']


    \_(ツ)_/

    Wednesday, January 23, 2019 8:06 AM
  • I have tested the code but doesn't work
    Wednesday, January 23, 2019 8:16 AM
  • The only way it won't work is if you have the name wrong.  Since we have no idea what $ExportItem is then there is no way to know what you are doing wrong.


    \_(ツ)_/

    Wednesday, January 23, 2019 8:28 AM
  • This is the whole code:

    $List = $Context.web.Lists.GetByTitle("MyList")
    $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
    $ListItems = $List.GetItems($Query)
    $context.Load($ListItems)
    $context.ExecuteQuery() 
    $ListItemCollection = @() 
    $ListItems | foreach {
    $ExportItem = New-Object PSObject
    $ExportItem | Add-Member -MemberType NoteProperty -name "Datum" -value $_["Datum"].ToLocalTime().ToString("dd-MM-yyyy");
    $ExportItem | Add-Member -MemberType NoteProperty -name "00:00 - 07:59" -value $_["00:00 - 07:59"]
    $ExportItem | Add-Member -MemberType NoteProperty -name "08:00 - 16:59" -value $_["08:00 - 16:59"]
    $ExportItem | Add-Member -MemberType NoteProperty -name "17:00 - 23:59" -value $_["17:00 - 23:59"]
    $ExportItem | Add-Member -MemberType NoteProperty -name "Opmerkingen" -value $_["Opmerkingen"]
    $ListItemCollection += $ExportItem
    }
    $ListItemCollection | epcsv "c:\Temp\MyList" -NoT

    Greetings, P

    Wednesday, January 23, 2019 8:31 AM
  • You are now posting versions of the same question in two other threads.

    Realize that the "title" of an item is not the name of the item.  You must use the name and not the title.


    \_(ツ)_/

    Wednesday, January 23, 2019 9:05 AM
  • Here is a utility script that will show you how to get the field details from all views in the list.

    https://gallery.technet.microsoft.com/SharePoint-Get-SPFields-49039dc0


    \_(ツ)_/

    Wednesday, January 23, 2019 9:09 AM