FrameworkTemplate/Solutions/Scripts/_ConfigMigration.ps1



if (!$Credentials) {
  $message = "Getting Credentials for $global:ServerUrl"
  Write-Host $message

  $Credentials = Get-Credential -Message "Credentials : $global:SolutionName @ $global:ServerUrl"
}
if (!$UserName)
{
$UserName =  $Credentials.GetNetworkCredential().UserName
$Password =  $Credentials.GetNetworkCredential().Password
}

if (!$conn) {
  [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
  [string]$CrmConnectionString = "AuthType=OAuth;Username=$UserName;Password=$Password;Url=$global:ServerUrl;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto"
  $conn = Get-CrmConnection -ConnectionString $CrmConnectionString -Verbose -MaxCrmConnectionTimeOutMinutes 5
}

if($conn.IsReady){


$message = "Exporting Configuration Data from $global:ServerUrl"
Write-Host $message


Write-Host("Exporting Configuration Data...")
Write-Host "Generating data package"
$packages = Get-CrmDataPackage -Conn $conn -Fetches @("<fetch>
  <entity name='theme'>
    <attribute name='themeid' />
    <attribute name='name' />
    <attribute name='type' />
    <attribute name='isdefaulttheme' />
    <order attribute='name' descending='false' />
    <filter type='and'>
      <condition attribute='name' operator='eq' value='CRM Blue Theme' />
    </filter>
  </entity>
</fetch>"
) -DisablePluginsGlobally $true #`
#|Add-FetchesToCrmDataPackage -Conn $conn -Fetches @("")


$packages.Data.InnerXml | Out-File -FilePath  (Join-Path $PSScriptRoot "..\ReferenceData\data.xml")
$packages.Schema.InnerXml | Out-File -FilePath (Join-Path $PSScriptRoot "..\ReferenceData\data_schema.xml")
}