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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Powershell to move word doc

(0) ShareShare
ReportReport
Posted on by 464

Has anyone used powershell to move word docs from one environment to another?  I don't want to use xrmtoolbox, if possible.

I have the same question (0)
  • Leah Ju Profile Picture
    Microsoft Employee on at

    Hi brownfield1,

    Or you can try to migrate data between Microsoft Dataverse environments using the dataflows OData connector

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/dataverse-odata-dataflows-migration 

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    hi

    it is possible to use PowerShell to move Word documents from one environment to another in Dynamics 365. Here's a basic script that you can use as a starting point:

    powershell:

    # Set variables

    $sourceUrl = "source.crm.dynamics.com"

    $sourceUsername = "sourceuser@domain.com"

    $sourcePassword = "sourcepassword"

    $sourceDocumentLibraryName = "Documents"

    $sourceDocumentName = "MyDocument.docx"

    $destinationUrl = "destination.crm.dynamics.com"

    $destinationUsername = "destinationuser@domain.com"

    $destinationPassword = "destinationpassword"

    $destinationDocumentLibraryName = "Documents"

    # Get source file

    $sourceContext = New-Object Microsoft.PowerShell.Commands.WebRequestSession

    $sourceContext.Credentials = New-Object System.Net.NetworkCredential($sourceUsername, $sourcePassword)

    $sourceFileUrl = "$sourceUrl/$sourceDocumentLibraryName/$sourceDocumentName"

    $sourceFileContent = Invoke-WebRequest -Uri $sourceFileUrl -WebSession $sourceContext

    $sourceFileBytes = [System.Convert]::FromBase64String($sourceFileContent.Content)

    # Upload file to destination

    $destinationContext = New-Object Microsoft.PowerShell.Commands.WebRequestSession

    $destinationContext.Credentials = New-Object System.Net.NetworkCredential($destinationUsername, $destinationPassword)

    $destinationFileUrl = "$destinationUrl/$destinationDocumentLibraryName/$sourceDocumentName"

    Invoke-RestMethod -Uri $destinationFileUrl -Method Put -Body $sourceFileBytes -WebSession $destinationContext

    You'll need to replace the values of the variables at the top of the script with your own environment information. The script uses the Invoke-WebRequest cmdlet to download the file from the source environment and the Invoke-RestMethod cmdlet to upload it to the destination environment.

    DAniele

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
iampranjal Profile Picture

iampranjal 41

#2
Martin Dráb Profile Picture

Martin Dráb 36 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans