Creating SharePoint Aspx Pages from Word Documents using PowerShell

Recently I worked on a solution that converts word documents to web pages in SharePoint, and I think it will be useful for a lot of people, particularly administrators who are looking for a way to convert existing word documents to web pages in SharePoint without having to do copy and paste and worry about how to format the text on the page. So I decided to make it available as a PowerShell script module that you can import and run with a single line of command.

This will be useful for organizations looking to make some documents available in read-only for their employees but wants to prevent them from downloading such documents, e.g policy documents may fall in this category. Aside using tools like right management system, one thing you may want to do is converting such documents to web pages. If this sounds like what you want, this PowerShell module is for you. 

To get started, download or clone the project file in GiHub. If you download it as a zip file, unzip it and copy the folder named ConvertWordDocument2AspxPage along with its content to Modules folder inside WindowsPowerShell directory in Program Files i.e. C:\Program Files\WindowsPowerShell\Modules.  Then follow the steps below to import the module and run the command.

1. Open PowerShell ISE or PowerShell command window 
2. Copy and paste the command below:

   Import-Module ConvertWordDocument2AspxPage 
   ConvertWordDocument2AspxPage -SiteUrl " " -TargetLibrary " " -Email " " -UserName " " -Password " "

Supply value for each of the parameter as explained below:

SiteUrl - Url of the site where the word document are located

TargetLibrary - Library where the documents are stored

Email - Email address that will receive notification when the page conversion finishes or error occurs

UserName - Username or email address of a user who have full control to the site and the library. This is used for authentication

Password - Password of the account used for authentication

Note: if you don't have access to Program Files. Copy the folder i.e. ConvertWordDocument2AspxPage  to any location of your choice. Then navigate to inside of the folder, and open the ConvertWordDocument2AspxPage.psm1 file. Change path of the dlls files to the location where you have copied the folder. 

Open PowerShell command and change the directory to where you have the ConvertWordDocument2AspxPage  and import the module using the command below:
Import-Module (Resolve-Path('ConvertWordDocument2AspxPage'))

Feel free to modify the source code for your specific requirements.

Note: I have only tested this with SharePoint modern pages but it should work for the classic pages as well.
Hope you find it useful. If will like to know anything, drop a comment or question in the comment area below. I will try my best to respond.

Update: if you get error: Add-Type : Could not load file or assembly 'file:///C:\Program 
Files\WindowsPowerShell\Modules\ConvertWordDocument2AspxPage\\DocumentFormat.OpenXml.dll' or one of its dependencies. Or other similar errors, you may need to download and install those dlls using Nuget Package manager in visual studio and copy the dlls to replace the versions in folder.
Note: Ignore the following error if you get it. The code runs regardless: Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Happy coding!!


  1. I got my expected result in the Final Microsoft Azure Fundamentals Exam. I had an outstanding experience with Microsoft AZ-900 Dumps and I recommend all to go for the Microsoft Azure Fundamentals Certification Exam preparation with this Microsoft AZ-900 PDF Dumps. I also used their Microsoft AZ-900 Practice Test Software and Microsoft AZ-900 Web-Based Test too for my preparation, which was very helpful in knowing and improving my mistakes.


Post a comment

Popular posts from this blog

Generate Word Document From A SharePoint List Item Using Microsoft Flow

Calling Microsoft Graph API from an Angular 5 Single Page Application (SPA)

Creating SharePoint Framework Client Web Part and solving the challenges with _RequestDigest Token value using React