SharePoint + PowerShell: Import All BDCM Files in a Directory and Set Permissions
In order to invest as little effort as possible creating and recreating and recreating my External Content Types on my development server, I exported the ECT's then deleted External Content Types, External Systems, and BDC Models. I saved them all in a directory on the SharePoint server, then I placed ImportALLbdcms.ps1 in the same directory and ran it.
$adminGroup = "DOMAIN\SharePoint Admins" #for bdc permissions $userGroup = "Domain\SharePoint Users"
$serviceContext = "https://localhost/" $nameSpace = "https://$env:USERDNSDOMAIN/".toLower()
$bdc = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType Catalog -ServiceContext $serviceContext $pathtobdcmfiles = Get-Location $importFiles = Get-Childitem -path $pathtobdcmfiles | Where {$_.extension -eq ".bdcm" -and $_.basename -ne "catalog"}
foreach ($file in $importFiles) { Import-SPBusinessDataCatalogModel -Path $file.FullName -Identity $bdc -force -ModelsIncluded -PropertiesIncluded -PermissionsIncluded -Verbose write-host $file.fullname }
$claimAdmin = New-SPClaimsPrincipal -Identity $adminGroup -IdentityType WindowsSamAccountName $claimUsers = New-SPClaimsPrincipal -Identity $userGrup -IdentityType WindowsSamAccountName
Grant-SPBusinessDataCatalogMetadataObject -Identity $bdc -Principal $claimAdmin -Right "Execute,SetPermissions,Edit,SelectableInClients" Grant-SPBusinessDataCatalogMetadataObject -Identity $bdc -Principal $claimUsers -Right "Execute,Edit,SelectableInClients"
Copy-SPBusinessDataCatalogAclToChildren -MetadataObject $bdc Sorry for a junky intro and no conclusion, I've been working 19 hour straight and I'm about exhausted. Anyway, HTHY!