2017-03-07 96 views
1

我想導出Dynamics CRM 365解決方案。像ALM Toolkit這樣的工具,例如沒有工作。Dynamics CRM導出解決方案(非本地)

我的問題:

1)是否有可能將整個CRM365解決方案通過PowerShell的所有出口?

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= Get-CrmConnection -OrganizationName MyOrg -DeploymentRegion MyRegion -OnLineType Office365 -Credential $credentials 

我可以讓組織沒有問題。但是,當我嘗試調用與此連接的導出方法獲得:

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解決方案呢?

回答

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); 
    } 
} 
相關問題