Dynamics CRM导出解决方案(非本地)

时间:2017-03-07 16:45:29

标签: powershell deployment dynamics-crm

我想导出Dynamics CRM 365解决方案。像ALM工具包这样的工具,例如没用。

我的问题:

1)是否可以通过powershell导出整个CRM365解决方案?

2)如果powershell不可能 - 是否可以通过c#?

我可以通过PowerShell连接到没有问题的crm。但如果我试着打电话

当我这样称呼时:

$domain = "https://mypath.com"
$username = "user"
$password = "password"
$secPassword = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secPassword.AppendChar($_)}
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secPassword

$conn = Get-CrmConnection -Url "https://mypath.com" -Credential $credentials 
$exportPath = "C:\Users\xy\Data" 
Import-Module "C:\Users\xy\Scripts\Adxstudio.Xrm.PowerShell\Adxstudio.Xrm.PowerShell.dll" 
Export-CrmContent -Connection $conn -OutputPath $exportPath -Uncompressed -Generalized

我收到以下错误:

Export-CrmContent : Metadata Contains A Reference That Cannot Be Resolved: "https://mypath/XRMServices/2011/Organization.svc?wsdl=wsdl0".
In C:\Users\my.ps1:14 Char:1
+ Export-CrmContent -Connection $conn -OutputPath $exportPath -Uncompre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Export-CrmContent], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Adxstudio.Xrm.PowerShell.Cmdlets.ExportCrmContent

但是如果我使用这个设置$ conn:

$conn= Get-CrmConnection -OrganizationName MyOrg -DeploymentRegion MyRegion -OnLineType Office365 -Credential $credentials 

我可以毫无问题地获得组织。但是当我尝试使用此连接调用export方法时,我得到:

The Parameter "$conn" cannot be bound. The value "Microsoft.Xrm.Tooling.Connector.CrmServiceClient" of the type "Microsoft.Xrm.Tooling.Connector.CrmServiceClient" can't be converted to "Adxstudio.Xrm.PowerShell.Cmdlets.PsCrmConnection".

有没有想法解决导出crm解决方案的两个问题之一?

1 个答案:

答案 0 :(得分:0)

未尝试过Powershell方法,but I've achieved this using C# in the past

static void ExportUnManagedSolutions(IOrganizationService service, String directory)
{
    //Find all the solutions
    QueryExpression query = new QueryExpression
    {
        EntityName = "solution",
        ColumnSet = new ColumnSet("friendlyname", "uniquename", "version"),
        Criteria = new FilterExpression()
        {
            Conditions =
            {
                //Unmanaged solutions only
                new ConditionExpression("ismanaged", ConditionOperator.Equal, false),

                //These are special CRM solutions, which are marked as unmanaged but cant actually be exported
                new ConditionExpression("friendlyname", ConditionOperator.NotEqual, "Active Solution"),
                new ConditionExpression("friendlyname", ConditionOperator.NotEqual, "Default Solution"),
                new ConditionExpression("friendlyname", ConditionOperator.NotEqual, "Basic Solution"),
            }
        }
    };

    EntityCollection solutions = service.RetrieveMultiple(query);

    //For each solution found
    foreach (Entity s in solutions.Entities)
    {
        Console.WriteLine("Exporting " + s["friendlyname"]);

        //Perform a solution export
        ExportSolutionRequest request = new ExportSolutionRequest();
        request.Managed = false;
        request.SolutionName = (String)s["uniquename"];

        ExportSolutionResponse response = (ExportSolutionResponse)service.Execute(request);

        byte[] exportXml = response.ExportSolutionFile;
        string filename = (String)s["uniquename"] + " " + (String)s["version"] + ".zip";

        //This assumes the file directory already exists
        File.WriteAllBytes(directory + filename, exportXml);

        Console.WriteLine("Solution exported to {0}.", directory + filename);
    }
}