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.

  • Suggested answer
    DAnny3211 Profile Picture
    9,278 Moderator on at
    RE: Powershell to move word doc

    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

  • Leah Ju Profile Picture
    Microsoft Employee on at
    RE: Powershell to move word doc

    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 

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans