PowerShell script to export a list to a CSV file
At home I use a SharePoint list as my primary address book (mainly to store addresses for family and friends). While building a custom backup script in PowerShell I added the following to export my Address Book list to a CSV file:
$AddressBookFile = “E:\Backup\addressbook.csv”
$Web = Get-SPWeb -Identity “http://portal.webbworld.local”
$List = $Web.Lists[“Address Book”]
$ListItemCollection = @()
$List.Items | foreach {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -Name “Name” -Value $_[“Last Name”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “First Name” -Value $_[“First Name”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “Home Phone” -Value $_[“Home Phone”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “Email Address” -Value $_[“Email Address”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “Address” -Value $_[“Address”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “City” -Value $_[“City”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “State/Province” -Value $_[“State/Province”]
$ExportItem | Add-Member -MemberType NoteProperty -Name “ZIP/Postal Code” -Value $_[“ZIP/Postal Code”]
$ListItemCollection += $ExportItem}
$ListItemCollection | Export-CSV $AddressBookFile -NoTypeInformation
$Web.Dispose()
![[BlogBookmark]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/blogbookmark.png)
![[Blogsvine]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/blogsvine.png)
![[del.icio.us]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/facebook.png)
![[Furl]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/furl.png)
![[Google]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/google.png)
![[LinkedIn]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/linkedin.png)
![[MySpace]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/myspace.png)
![[Reddit]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Twitter]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.adventuresinsharepoint.co.uk/wp-content/plugins/bookmarkify/email.png)
This is excellent, thanks for taking the time to share it.