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.

 1$adminGroup = "DOMAIN\SharePoint Admins" # for bdc permissions
 2$userGroup  = "Domain\SharePoint Users"
 3
 4$serviceContext = "https://localhost/"
 5$nameSpace      = "https://$env:USERDNSDOMAIN/".ToLower()
 6
 7$bdc = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType Catalog -ServiceContext $serviceContext
 8
 9$pathtobdcmfiles = Get-Location
10$importFiles = Get-ChildItem -Path $pathtobdcmfiles | Where-Object { $_.Extension -eq ".bdcm" -and $_.BaseName -ne "catalog" }
11
12foreach ($file in $importFiles) {
13    Import-SPBusinessDataCatalogModel -Path $file.FullName -Identity $bdc -Force -ModelsIncluded -PropertiesIncluded -PermissionsIncluded -Verbose
14    Write-Host $file.FullName
15}
16
17$claimAdmin = New-SPClaimsPrincipal -Identity $adminGroup -IdentityType WindowsSamAccountName
18$claimUsers = New-SPClaimsPrincipal -Identity $userGroup  -IdentityType WindowsSamAccountName
19
20Grant-SPBusinessDataCatalogMetadataObject -Identity $bdc -Principal $claimAdmin -Right "Execute,SetPermissions,Edit,SelectableInClients"
21Grant-SPBusinessDataCatalogMetadataObject -Identity $bdc -Principal $claimUsers -Right "Execute,Edit,SelectableInClients"
22
23Copy-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!