I am trying to use powershell for importing a resource file in Business Data Catalog but I keep getting the following error
Import-SPBusinessDataCatalogModel : The root element of a valid
Metadata package must be 'Model' in namespace
'http://schemas.microsoft.com/windows/2007/BusinessDataCatalog'. The root in the given package is 'Model' in namespace'http://schemas.microsoft.com/windows/2007/BusinessDataCatalog/Resources'.
Error was encountered at or just before Line: '2' and Position: '2'. At M:\PowerShell\ImportModel.ps1:13 char:35
+ Import-SPBusinessDataCatalogModel <<<< -Path $file.FullName -Identity $bdc -force -ModelsIncluded -PropertiesIncluded -Verbose
+ CategoryInfo : InvalidData: (Microsoft.Share...alogModelCmdlet:SPImportSPBusinessDataCatalogModelCmdlet)
[Impo rt-SPBusinessDataCatalogModel], PackageFormatException
+ FullyQualifiedErrorId : Microsoft.SharePoint.BusinessData.SharedService.SPImportSPBusinessDataCatalogModelCmdlet
When I manualy import the resource file everything is ok.
This is the resource file i Use
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<Model xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog/Resources" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="CZ.Sharepoint.BCS.Correspondentie.Zorg">
<LobSystems>
<LobSystem Name="Correspondentie">
<Properties>
<Property Name="WildcardCharacter" Type="System.String">%</Property>
</Properties>
<LobSystemInstances>
<LobSystemInstance Name="Correspondentie">
<Properties>
<Property Name="AuthenticationMode" Type="System.String">PassThrough</Property>
<Property Name="DatabaseAccessProvider" Type="System.String">SqlServer</Property>
<Property Name="RdbConnection Data Source" Type="System.String">TSTSQL10</Property>
<Property Name="RdbConnection Initial Catalog" Type="System.String">PRD_Correspondentie</Property>
<Property Name="RdbConnection Integrated Security" Type="System.String">SSPI</Property>
<Property Name="RdbConnection Pooling" Type="System.String">True</Property>
<Property Name="ShowInSearchUI" Type="System.String"></Property>
</Properties>
</LobSystemInstance>
</LobSystemInstances>
</LobSystem>
</LobSystems>
</Model>
And the powershell script
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$serviceContext = "http://localhost/"
$bdc = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType Catalog -ServiceContext $serviceContext
$pathtobdcmfiles = Get-Location
$importFiles = Get-Childitem -path $pathtobdcmfiles | Where {$_.extension -eq ".bdcr" -and $_.basename -ne "catalog"}
foreach ($file in $importFiles) {
Import-SPBusinessDataCatalogModel -Path $file.FullName -Identity $bdc -force -ModelsIncluded -PropertiesIncluded -Verbose
write-host $file.fullname
}