none
Export SP list (Enhanced rich text to Plain Text) RRS feed

  • Question

  • Good day! I have the below PowerShell to export a list. It works as intended, however the Resolution field is coming out with HTML tags. Can someone assist with the correct output?

    Thanks,
    Lee

    #Load SharePoint CSOM Assemblies
    Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll"
    ##Variables for Processing
    $SiteUrl = "https://xxx/sites/xxx"
    $ListName="HelpDesk"
    $ExportFile ="C:\Users\xxx\Desktop\HD-export1.csv"
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    #Get the List
    $List = $Context.web.Lists.GetByTitle($ListName)
    $Context.Load($List.Views)
    $Context.ExecuteQuery()
    $view=$List.Views.GetByTitle("FY20 - Chris Closed")
    $Context.Load($view)
    $Context.ExecuteQuery()
    $CAMLQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $CAMLQuery.ViewXml = "<View><Query>"+ $View.ViewQuery +"</Query></View>"
    $ListItems = $List.GetItems($CAMLQuery)
    $context.Load($ListItems)
    $context.ExecuteQuery()
    #Array to Hold List Items
    $ListItemCollection = @()
    #Fetch each list item value to export to excel
     $ListItems |  foreach {
        $ExportItem = New-Object PSObject
        $ExportItem | Add-Member -MemberType NoteProperty -name "Ticket Number" -value $_["Title"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Created" -value $_["Created"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Created Day Name" -value $_["Created_x0020_Day_x0020_of_x0020"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Core Hour / Non Core" -value $_["Core_x0020_Hr_x0020_Tickets"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Assigned Date" -value $_["Assigned_x0020_Date"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Closed Date" -value $_["Date_x0020_Ticket_x0020_Closed"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Time to Assign" -value $_["Time_x0020_to_x0020_Assign"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Total Time Open" -value $_["Total_x0020_time_x0020_open"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Who is requesting help?" -value $_["Whoisrequestinghelp"].LookupValue
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Primary Issue" -value $_["field7"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Secondary Issue" -value $_["field8"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Status" -value $_["TechStatus"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "IMO Tech" -value $_["imotech"].LookupValue
        $ExportItem | Add-Member -MemberType NoteProperty -Name "Resolution" -value $_["Resolution"]
        $ExportItem | Add-Member -MemberType NoteProperty -Name "ECN" -value $_["_x0065_cn2"]
       
        #Add the object with above properties to the Array
        $ListItemCollection += $ExportItem
     }
    #Export the result Array to CSV file
    $ListItemCollection | Export-CSV $ExportFile -NoTypeInformation


    Lee Mossolle

    Friday, November 8, 2019 4:14 PM

Answers

  • Hi,

    What type of column is this Resolution field? I think it is the correct output based on your script.

    You can see the sample script below and see if it works.

    Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
      
    #Variables
    $SiteUrl="<SiteURL>"
    $ListName="<ListName>"
    $OutPutFile = "<FilePath>"
    $ListViewName = "<ListViewName>"
      
    #Get Web and List
    $web = Get-SPWeb $SiteUrl
    $List = $Web.Lists[$ListName]
    #Get the View
    $view = $list.Views[$ListViewName]
    $ViewFields = $view.viewFields
    #Get All items from the view
    $items = $list.GetItems($view)
    
    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
    
    #Get All List items
    $items | ForEach { 
        $ExportItem = New-Object PSObject  
        foreach($Field in $ViewFields)
        {
            $ExportItem | Add-Member -MemberType NoteProperty -name $Field -value $_[$Field] 
        }
        #Add the object with property to an Array
        $ListItemCollection += $ExportItem
    }   
    #Export the result Array to CSV file
    $ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation
    Write-host -f Green "Complete"

    Here’s your reference.

    Export SharePoint List Items to CSV using PowerShell.

    Please note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, November 11, 2019 9:40 AM

All replies

  • Hi,

    What type of column is this Resolution field? I think it is the correct output based on your script.

    You can see the sample script below and see if it works.

    Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
      
    #Variables
    $SiteUrl="<SiteURL>"
    $ListName="<ListName>"
    $OutPutFile = "<FilePath>"
    $ListViewName = "<ListViewName>"
      
    #Get Web and List
    $web = Get-SPWeb $SiteUrl
    $List = $Web.Lists[$ListName]
    #Get the View
    $view = $list.Views[$ListViewName]
    $ViewFields = $view.viewFields
    #Get All items from the view
    $items = $list.GetItems($view)
    
    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
    
    #Get All List items
    $items | ForEach { 
        $ExportItem = New-Object PSObject  
        foreach($Field in $ViewFields)
        {
            $ExportItem | Add-Member -MemberType NoteProperty -name $Field -value $_[$Field] 
        }
        #Add the object with property to an Array
        $ListItemCollection += $ExportItem
    }   
    #Export the result Array to CSV file
    $ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation
    Write-host -f Green "Complete"

    Here’s your reference.

    Export SharePoint List Items to CSV using PowerShell.

    Please note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, November 11, 2019 9:40 AM
  • Hi,

    I'm checking how it is going on with this issue.

    Please remember to update this thread if you have any progress.

    Thank you for your understanding.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, November 15, 2019 8:24 AM