I’m getting information from a SharePoint list, using the following script.
The fields Progress, Problems, & Plans are enhanced rich text. The HTML in some records is causing a shift on the export, so I’m trying to clear out the HTML from the strings. If I take out these lines, it works fine. When I add the 3 lines, my output list only “Length”.
So, my question is what am I doing wrong? My understanding is that I need to convert the strings to objects, but that’s what I’m doing when I create the PSObject. I’m learning as I go here, so bare with me.
$Progress -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","" $Problems -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","" $Plans -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>",""
function Get-3P() { $numDays = 5 $toDate = Get-Date $toDate = $toDate.AddDays(-$numDays) #$toDate = Get-Date (2016-01-01) $site = Get-SPSite http://mysitecollection $serverContext=[Microsoft.Office.Server.ServerContext]::GetContext($site) $upm=New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serverContext) $spWeb = Get-SPWeb http://myweb $spList = $spWeb.Lists["Report 3Ps"] #Get list instance $spListItems = $spList.Items foreach ($item in $spListItems){ if($item["Created"] -gt $toDate){ $dateWeekEnding = $item["Week of"] $dateWeekEnding = $dateWeekEnding.Substring($dateWeekEnding.get_Length()-10) $Lookup = new-object Microsoft.SharePoint.SPFieldLookupValue($item["Created By"]) $User = $Lookup.LookupValue; $Progress = $item["Progress"] $Progress -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","" $Problems = $item["Problems"] $Problems -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","" $Plans = $item["Plans"] $Plans -replace "]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","" $data = @{ "Week Ending" = $dateWeekEnding "Progress" = $Progress "Problems" = $Problems "Plans" = $Plans "Created By" = $User "Created Date" = $item["Created"] "Modified Date" = $item["Modified"] } New-Object PSObject -Property $data | Select "Week Ending", "Progress", "Problems", "Plans", "Created By", "Created Date", "Modified Date" } } } Get-3P | Export-Csv -NoTypeInformation -Path C:\Temp\Export-2016-3Ps.csv