web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Powershell script to export solution not working in Dynamics 365 CE

(0) ShareShare
ReportReport
Posted on by 2,745 User Group Leader

Hi Experts,

I am trying to export crm solution from online D365E using powershell script but i am getting error.

my script below:

#Powershell script for exporting the solution from the source environment.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
$solutionName ="BuildAutomate"
$path = "D:\"
Set-StrictMode -Version latest
function InstallModule{
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
$moduleName = "Microsoft.Xrm.Data.Powershell"
$moduleVersion = "2.7.2"
if (!(Get-Module -ListAvailable -Name $moduleName )) {
Write-host "Module Not found, installing now"
$moduleVersion
Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force
}
else
{
Write-host "Module Found"
}
}
function GetCrmConn{
param(
[string]$user,
[string]$secpasswd,
[string]$crmUrl)
Write-Host "UserId: $user Password: $secpasswd CrmUrl: $crmUrl"
$secpasswd2 = ConvertTo-SecureString -String $secpasswd -AsPlainText -Force
write-host "Creating credentials"
$mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd2)
write-host "Credentials object created"
write-host "Establishing crm connection next"
$crm = Connect-CrmOnline -Credential $mycreds -ServerUrl $CrmUrl
write-host "Crm connection established"
return $crm
}
InstallModule
#Update Source CRM instance details below:
Write-Host "going to create first connection"
$Crm1 = GetCrmConn -user "<username>" -secpasswd "<password>" -crmUrl "<url1>"
Write-Host "first connection created"
Set-CrmConnectionTimeout -conn $Crm1 -TimeoutInSeconds 6000
#Update target CRM instance below:
Write-Host "going to create second connection"
$Crm2 = GetCrmConn -user "<username>" -secpasswd "<password>" -crmUrl "<url2"
Write-Host "second connection created"

Write-Host "Exporting Solution"
Export-CrmSolution -conn $Crm1 -SolutionName "BuildAutomate" -Managed -SolutionFilePath "C:\" -SolutionZipFileName "MySolution_Managed.zip"
Write-Host "Solution Exported"

The error I am getting:Exporting Solution
Get-CrmRecordsByFetch : System.Management.Automation.RuntimeException: Crm Service not initialized
Crm Service not initialized
At C:\Program Files\WindowsPowerShell\Modules\Microsoft.Xrm.Data.Powershell\2.8.11\Microsoft.Xrm.Data.Powershell.psm1:3368 char:20
+ ... $results = Get-CrmRecordsByFetch -conn $conn -Fetch $fetch -TopCount ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-CrmRecordsByFetch

Export-CrmSolution : System.Management.Automation.RuntimeException: Crm Service not initialized
Crm Service not initialized
At C:\Users\Softchief\Source\Repos\BuildAutomate\BuildAutomate.SolutionManager\SolutionExportDev.ps1:48 char:1
+ Export-CrmSolution -conn $Crm1 -SolutionName "BuildAutomate" -Managed ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Export-CrmSolution

I have the same question (0)
  • Pankaj Gogoi Profile Picture
    3,177 on at

    Maybe it's a versioning issue. Please check which version you are using.

    Best Regards

    PG

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Check below links.

    www.itaintboring.com/.../

    thatcrm.com/.../

    Please mark my answer verified if i were helpful

  • Tanmoy Dutta Profile Picture
    10 on at

    Hi,

    Are you able to solve that problem as I am getting the same problem and didn't find any clue till now.

    Here is my PowerShell Script -

    ==================

    $SolutionName ="DemoSolution"

    $SolutionFilePath="C:\Users\TanmoyDutta\source\repos\Dynamics365Pilot\Dynamics365Demo.Solutions\DemoSolution"

    $CRMSourceUserName="XXXXXXXXX@XXXX.onmicrosoft.com"

    $CRMSourcePassword="XXXXXXXXX"

    $CRMSourceUrl="devtanmoy.crm8.dynamics.com"

    Set-StrictMode -Version latest

    function InstallRequiredModule {

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force

    $moduleName = "Microsoft.Xrm.Data.Powershell"

    $moduleVersion = "2.7.2"

    if (!(Get-Module -ListAvailable -Name $moduleName )) {

    Write-host "Module Not found, installing now $moduleVersion"

    Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force

    }

    else {

    Write-host "Module Found"

    }

    }

    function EstablishCRMConnection {

    param(

    [string]$crmUserName,

    [string]$crmSecPasswd,

    [string]$crmUrl)

    Write-Host "UserId: $crmUserName Password: $crmSecPasswd CrmUrl: $crmUrl"

    $CRMSecPasswdString = ConvertTo-SecureString -String $crmSecPasswd -AsPlainText -Force

    write-host "Creating credentials"

    $Credentials = New-Object System.Management.Automation.PSCredential ($crmUserName, $CRMSecPasswdString)

    write-host "Credentials object created"

    write-host "Establishing crm connection next"

    $crm = Connect-CrmOnline -Credential $Credentials -ServerUrl $CrmUrl

    write-host "Crm connection established"

    return $crm

    }

    #Update Source CRM instance details below:

    Write-Host "going to create source connection 1"

    $CrmConnection1 = EstablishCRMConnection -crmUserName "$CRMSourceUserName" -crmSecPasswd "$CRMSourcePassword" -crmUrl "$CRMSourceUrl" -Verbose

    Write-Host "Source connection 1 created"

    Set-CrmConnectionTimeout -conn $CrmConnection1 -TimeoutInSeconds 1000

    Write-Host "going to create source connection 2"

    $CrmConnection2 = EstablishCRMConnection -crmUserName "$CRMSourceUserName" -crmSecPasswd "$CRMSourcePassword" -crmUrl "$CRMSourceUrl" -Verbose

    Write-Host "Source connection 2 created"

    Write-Host "Exporting Solution"

    Export-CrmSolution -conn $CrmConnection2 -SolutionName "$SolutionName" -SolutionFilePath "$SolutionFilePath" -SolutionZipFileName "$SolutionName.zip" -Verbose

    Write-host "Solution Exported"

    Here is the result I am getting from Terminal Result as Defect -

    =======================================

    going to create source connection 1

    UserId: XXXXX@XXXXX.onmicrosoft.com Password: XXXXXXXXXXX CrmUrl: devtanmoy.crm8.dynamics.com

    Creating credentials

    Credentials object created      

    Establishing crm connection next

    Crm connection established

    Source connection 1 created

    WARNING: Please reconnect to the service after setting the connection timeout or the new timeout will *not* be used for operations.

    going to create source connection 2

    UserId: XXXXX@XXXXX.onmicrosoft.com Password: XXXXXXXXXXX CrmUrl: devtanmoy.crm8.dynamics.com

    Creating credentials

    Credentials object created

    Establishing crm connection next

    Crm connection established

    Source connection 2 created

    Exporting Solution

    VERBOSE: Using the supplied single filter of uniquename 'like' DemoSolution

    Get-CrmRecordsByFetch : System.Management.Automation.RuntimeException: Crm Service not initialized

    Crm Service not initialized

    At C:\Program

    Files\WindowsPowerShell\Modules\Microsoft.Xrm.Data.Powershell\2.8.11\Microsoft.Xrm.Data.Powershell.psm1:3368 char:20  

    + ...  $results = Get-CrmRecordsByFetch -conn $conn -Fetch $fetch -TopCount ...

    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

       + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException

       + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-CrmRecordsByFetch

    Export-CrmSolution : System.Management.Automation.RuntimeException: Crm Service not initialized

    Crm Service not initialized

    At C:\Users\TanmoyDutta\source\repos\Dynamics365Pilot\Dynamics365Demo.SolutionManager\SolutionExport.ps1:46 char:1    

    + Export-CrmSolution -conn $CrmConnection2 -SolutionName "$SolutionName ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

       + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException

       + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Export-CrmSolution

    Solution Exported

    Thanks & Regards,

    Tanmoy

  • Tanmoy Dutta Profile Picture
    10 on at

    Hi @Pankaj G,

    I'm not sure which version conflict you are talking about. Can you little brief how can I solve that.

    Thanks & Regards,

    Tanmoy

  • Suggested answer
    Pankaj Gogoi Profile Picture
    3,177 on at

    Maybe this will help. Please check if old dlls are being referenced.

    docs.microsoft.com/.../use-powershell-cmdlets-xrm-tooling-connect

    https://www.itaintboring.com/dynamics-crm/using-powershell-to-exportimport-solutions-data-and-word-templates/

    Good Luck

    Best Regards

    PG

  • geophray Profile Picture
    5 on at

    Were you able to resolve this issue Tanmoy? I've run up against the same thing and have yet to reach a solution with the Microsoft.Xrm.Data.Powershell library. I have successfully connected and retrieved the organizations I have access to as outlined in the Microsoft Docs but when attempting to export my solution I continue to get the same error message you received... that the Crm Service is not initialized.  I have yet to find any solution that solves this issue, so any insights you have gleaned would be highly appreciated.

  • Suggested answer
    Abhishek Dhoriya Profile Picture
    1,013 on at

    You can follow the below Video article , where it explained step by step process of how you can export a default solution programmatically, with simple and easy to follow guidance and scripts.

    Export default solution in Dynamics 365 / CRM Programmatically

    Hope this will help , mark this answer as Verified , if this helped you it will give others a confidence and get the right assistance at right time :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 53 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans