Hello,
I'm attempting to export an external list to a CSV file using power shell. I already have a script to export SharePoint lists, however, it hasn't worked but gave me the below error.
An error occurred while enumerating through a collection: The shim execution failed unexpectedly - Could not load file or assembly 'System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)..
At C:\ExportListToCSV\Test.ps1:33 char:8
+ foreach <<<< ($eitem in $eitems) {
+ CategoryInfo : InvalidOperation: (Microsoft.Share...tanceEnumerator:SPEntityInstanceEnumerator) [], RuntimeException
+ FullyQualifiedErrorId : BadEnumeration
After doing some searching I came across a blog suggesting to add the below two statements, however, I'm still getting the same error. Now, the blog was referring to SharePoint 2013 while mine is 2010.
$ctx = Get-SPServiceContext http://sharepoint.domain.com/
$scope = new-object Microsoft.SharePoint.SPServiceContextScope $ctx
Below is the powershell script I am using. Can someone point me in the right direction?
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#lines only for calling External Lists
$ctx = Get-SPServiceContex http://sharepoint.domain.com/write-host "CTX " $ctx
$scope = new-object Microsoft.SharePoint.SPServiceContextScope $ctx
write-host "Scope " $scope
#Get the Web
$web = Get-SPWeb -identity http://sharepoint.domain.com/sites/level1
#Get the Target List
$elist = $web.Lists["ProductInventory"]
Write-Host The external list contains $elist.Items.Count items
#Get the target items
$eitems = $elist.GetItems()
foreach ($eitem in $eitems) {
$ExportItem = New-Object PSObject
#$ExportItem | Add-Member -MemberType NoteProperty -name "ItemID" -value $_["ItemID"]
$ExportItem | Add-Member -MemberType NoteProperty -name "ProductID" -value $_["ProductID"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Name" -value $_["Name"]
$ExportItem | Add-Member -MemberType NoteProperty -name "MakeFlag" -value $_["MakeFlag"]
$ExportItem | Add-Member -MemberType NoteProperty -name "FinishedGoodsFlag" -value $_["FinishedGoodsFlag"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Color" -value $_["Color"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "SafetyStockLevel" -value $_["SafetyStockLevel"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "ReorderPoint" -value $_["ReorderPoint"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "StandardCost" -value $_["StandardCost"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "ListPrice" -value $_["ListPrice"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Size" -value $_["Size"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "SizeUnitMeasureCode" -value $_["SizeUnitMeasureCode"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Weight" -value $_["Weight"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "DaysToManufacture" -value $_["DaysToManufacture"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "ProductLine" -value $_["ProductLine"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Class" -value $_["Class"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "Style" -value $_["Style"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "ProductSubcategoryID" -value $_["ProductSubcategoryID"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "SellStartDate" -value $_["SellStartDate"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "SellEndDate" -value $_["SellEndDate"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "DiscontinuedDate" -value $_["DiscontinuedDate"]
$ExportItem | Add-Member -MemberType NoteProperty -Name "ModifiedDate" -value $_["ModifiedDate"]
#Add the object with property to an Array
$ListItemCollection += $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV "D:\Install\scripts\ExportListToCSV\TestProductInventory\output.csv" -NoTypeInformation
#Dispose the web Object
$web.Dispose()