magritton
11/29/2017 - 7:54 PM

PS SP Export List to CSV

This exports a list to a CSV file with custom fields

$site = Get-SPweb "https://xxx/web"

$mList=$site.Lists["Work Log"]
$i = 0

#$mList.Items #| Export-Csv F:\temp\WorkLog.txt

#$item = $mList.Items[2]

$exportlist = @()

foreach($f in $mList.Items)
{
	$NameSplitted = $f["Name"].Split("#")
	#$NameSplitted[1]
	$i
	$info = @{
		"TitleProject" = $f["Title"]
		"Date" = $f["Date"]
		"Location" = $f["Location"]
		"Network" = $f["Network"]
		"Branch" = $f["Branch_x0020_Category"]
		"Task" = $f["Category"]
		"TimeSpent" = $f["Time_x0020_Spent"]
		"RGOT" = $f["RG_x002f_OT"]
		"Notes" = $f["Notes"]
		"Name" = $NameSplitted[1]
	}

	$obj = New-Object -TypeName PSObject -Property $info
	$exportlist += $obj
	$i++
}
$exportlist | Export-Csv -Path "F:\temp\WorkLog.csv"