Giter VIP home page Giter VIP logo

theohbrothers / convertonenote2markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sjoerdv/convertonenote2markdown

590.0 7.0 71.0 290 KB

Ready to make the step to Markdown and saying farewell to your OneNote, EverNote or whatever proprietary note taking tool you are using? Nothing beats clear text, right? Read on!

License: GNU General Public License v3.0

PowerShell 100.00%
markdown onenote converter pandoc onetastic obsidian commonmark github-flavored-markdown commonmark-extension multimarkdown php-markdown vanilla-markdown joplin powershell pwsh

convertonenote2markdown's Introduction

Convert OneNote to MarkDown

github-actions github-release

Ready to make the step to Markdown and saying farewell to your OneNote, EverNote or whatever proprietary note taking tool you are using? Nothing beats clear text, right? Read on!

The powershell script ConvertOneNote2MarkDown-v2.ps1 will utilize the OneNote Object Model on your workstation to convert all OneNote pages to Word documents and then utilizes Pandoc to convert the Word documents to Markdown (.md) format.

Summary

  • Choose between converting a specific notebook or all notebooks in OneNote. Only notebooks which are open and synchronized in OneNote can be converted.
  • Choose to do a dry run or run the actual conversion.
  • Create a folder structure for your Notebooks and Sections
    • Process pages that are in sections at the Notebook, Section Group and all Nested Section Group levels
  • Choose between creating subfolders for subpages (e.g. Page\Subpage.md) or appending prefixes (e.g. Page_Subpage.md)
  • Specify a value between 32 and 255 as the maximum length of markdown file names, and their folder names (only when using subfolders for subpages (e.g. Page\Subpage.md). A lower value can help avoid hitting file and folder name limits of 255 bytes on file systems. A higher value preserves a longer page title. If using page prefixes (e.g. Page_Subpage.md), it is recommended to use a value of 100 or greater.
  • Choose between putting all media (images, attachments) in a central /media folder for each notebook, or in a separate /media folder in each folder of the hierarchy
    • Symbols in media file names removed for link compatibility
    • Updates media references in the resulting .md files, generating relative references to the media files within the markdown document
  • Choose between discarding or keeping intermediate Word files. Intermediate Word files are stored in a central notebook folder.
  • Choose between converting from existing .docx (90% faster) and creating new ones - useful if just want to test differences in the various processing options without generating new .docxeach time
  • Choose between naming .docx files using page ID and last modified epoch date e.g. {somelongid}-1234567890.docx or hierarchy e.g. <sectiongroup>-<section>-<page>.docx
  • specify Pandoc output format and any optional extensions, defaulting to Pandoc Markdown format which strips most HTML from tables and using pipe tables. Customize this to get the desired Markdown flavor. See more details on these options here:
    • markdown (Pandoc Markdown)
    • commonmark (CommonMark Markdown)
    • gfm (GitHub-Flavored Markdown), or the deprecated and less accurate markdown_github; use markdown_github only if you need extensions not supported in gfm.
    • markdown_mmd (MultiMarkdown)
    • markdown_phpextra (PHP Markdown Extra)
    • markdown_strict (original unextended Markdown)
    • Improved headers, with title now as a # heading, standardized DateTime format for created and modified dates, and horizontal line to separate from rest of document
  • Choose whether to clear extra newlines between unordered (bullet) and ordered (numbered) list items, non-breaking spaces from blank lines, and > after unordered lists, which are created when converting with Pandoc
  • Choose whether to remove \ escape symbol that are created when converting with Pandoc
  • Choose whether to use Line Feed (LF) or Carriage Return + Line Feed (CRLF) for new lines
  • Choose whether to include a .pdf export alongside the .md file. .md does not preserve InkDrawing (i.e. overlayed drawings, highlights, pen marks) absolute positions within a page, but a .pdf export is a complete page snapshot that preserves InkDrawing absolute positions within a page.
  • Detailed logs. Run the script with -Verbose to see detailed logs of each page's conversion.

Known Issues

  1. If there are any collapsed paragraphs in your pages, the collapsed/hidden paragraphs will not be exported in the final .md file
    • You can use the included Onetastic Macro script to automatically expand all paragraphs in each Notebook
    • Download Onetastic here and, once installed, use New Macro > File > Import to install the attached .xml macro file within Onetastic
  2. Password protected sections should be unlocked before continuing, the Object Model does not have access to them if you don't
  3. You should start by "flattening" all InkDrawing (i.e. pen/hand written elements) in your onennote pages. Because OneNote does not have this function you will have to take screenshots of your pages with pen/hand written notes and paste the resulting image and then remove the scriblings. If you are a heavy pen user this is a very cumbersome.
    • Alternatively, if you are converting a notebook only for reading sake, and want to preserve all notes layout, instead of flattening all InkDrawing manually, you may prefer to export a .pdf which preserves the full apperance and layout of the original note (including InkDrawing). Simply use the config option $exportPdf = 2 to export a .pdf alongisde the .md file.
  4. While running the conversion OneNote will be unusable and it is recommended to walk away and have some coffee as the Object Model might be interrupted if you do anything else.
  5. Linked file object in .md files are clickable in VSCode, but do not open in their associated program, you will have to open the files directly from the file system.

Requirements

Usage

  1. Clone or download the repository to acquire the powershell script.

  2. Start the OneNote application (may require opening as Adminstrator in some cases). Keep OneNote open during the conversion.

  3. It is advised that you install Onetastic and the attached macro, which will automatically expand any collapsed paragraphs in the notebook. They won't be exported otherwise.

    • To install the macro, click the New Macro Button within the Onetastic Toolbar and then select File > Import and select the .xml macro included in the release.
    • Run the macro for each Notebook that is open
  4. It is highly recommended that you use VS Code, and its embedded Powershell terminal, as this allows you to edit and run the script, as well as check the results of the .md output all in one window.

  5. If you prefer to use a configuration file, rename config.example.ps1 to config.ps1 and configure options in config.ps1 to your liking.

    • You may like to use $dryRun = 1 to do a dry run first. This is useful for trying out different settings until you find one you like.
  6. Whatever you choose, open Powershell as Administrator (or VSCode as Administrator, with Powershell as the integrated terminal).

    • In Powershell, first navigate to the folder containing the script:
    cd "C:\path\to\ConvertOneNote2Markdown"
    • Then run the script:
    .\ConvertOneNote2MarkDown-v2.ps1
    • If you would like to see detailed logs about the conversion process, use the -Verbose switch:
    .\ConvertOneNote2MarkDown-v2.ps1 -Verbose
    • By default, the script does not terminate on any errors during conversion, but it keeps continuing. If you would like the script to terminate immediately on any error it encounters, use the -ErrorAction Stop switch (That way, if the script finishes without errors, you can be sure the entire conversion process went perfectly):
    .\ConvertOneNote2MarkDown-v2.ps1 -ErrorAction Stop
    Set-ExecutionPolicy Bypass -Scope Process -Force
    • If you see any other errors, check the FAQ.
  7. If you chose to use a configuration file config.ps1, skip to the next step. If you did not choose to use a configuration file, the script will ask you for configuration interactively.

    • It starts off asking whether to do a dry run. This is useful for trying out different settings until you find one you like.
    • It will ask you for the path to store the markdown folder structure. Please use an empty folder. If using VS Code, you might not be able to paste the filepath - right click on the blinking cursor and it will paste from clipboard. Use a full absolute path.
    • Read the prompts carefully to select your desired options. If you aren't actively editing your pages in OneNote, it is highly recommended that you don't delete the intermediate word docs, as they take 80+% of the time to generate. They are stored in their own folder, out of the way. You can then quickly re-run the script with different parameters until you find what you like.
  8. Sit back and wait until the process completes.

  9. To stop the process at any time, press Ctrl+C.

  10. If you like, you can inspect some of the .md files prior to completion. If you're not happy with the results, stop the process, delete the .md and media folders and re-run with different configuration options.

    • If you want to convert to Obsidian Markdown, try any of these recommendations (see here, here):
    $conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables-bracketed_spans+native_spans+startnum'
    $conversion = 'markdown_mmd-simple_tables-multiline_tables-grid_tables+pipe_tables-mmd_link_attributes'
    • If you want to convert to GitHub Flavored Markdown, try this (see here):
    $conversion = 'gfm+pipe_tables-raw_html'
    • If you do not want the line of image dimensions after each image, e.g. {width="12.072916666666666in" height="6.65625in"} in markdown, try this (see here):
    $conversion = 'gfm+pipe_tables-raw_html'

Results

The script will log any errors encountered during and at the end of its run, so please review, fix and run again if needed.

If you are satisfied check the results with a markdown editor like VSCode. All images should popup just right in the Preview Pane for Markdown files.

Recommendations

  1. I'd like to strongly recommend the VS Code Foam extension, which pulls together a selection of markdown-related extensions to become a comprehensive knowledge management tool.
  2. I'd also like to recommend Obsidian.md, which is another fantastic markdown knowledge management tool.
  3. Some other VSCode markdown extensions to check out are:

Note: The bottom three are not really markdown related but are quite obvious.

code `
  --install-extension davidanson.vscode-markdownlint `
  --install-extension ms-vscode.powershell-preview `
  --install-extension jebbs.markdown-extended `
  --install-extension telesoho.vscode-markdown-paste-image `
  --install-extension redhat.vscode-yaml `
  --install-extension vscode-icons-team.vscode-icons `
  --install-extension ms-vsts.team

FAQ

Q: How to install and run Powershell 7.0.x?

A: To install Powershell 7.0.13 (the highest supported version of Powershell) without overridding any existing version of Powershell Core on your system, download PowerShell-7.0.13-win-x64.zip (validate its checksum here), extract it to a directory C:\PowerShell-7.0.13-win-x64, and run C:\PowerShell-7.0.13-win-x64\pwsh.exe.

To uninstall after your are done converting, simply delete the C:\PowerShell-7.0.13-win-x64 directory.

Q: Why is Powershell Core 7.1 and above unsupported?

A: Powershell 7.1.x and above no longer supports loading Win32 GAC Assemblies, which is needed for interacting with the OneNote Desktop APIs. It is very unlikely that Microsoft will add support for later Powershell Core versions, since Win32 is starting to become deprecated.

Q: How to install Pandoc?

A: Pandoc can be installed in any of the following ways:

  • Download pandoc Windows .msi installer. During installation, ensure Pandoc is installed for all users (by checking the box Install for all users of thie machine), which is needed for Pandoc to be available to Administrator.
  • Use Chocolatey to install the Pandoc package on Windows.

After installing, ensure to restart Powershell or the computer for Pandoc to be set correctly in PATH.

Q: Error(s) when opening OneNote as Administrator

A: If there are errors opening OneNote as Administrator, just open it normally without Administrator permissions. A user has reported successful conversion with only Powershell opened as Administrator. See case.

Q: Some notebooks are not detected / converted

A: The script cannot detect notebooks which are not yet open in OneNote. Use File > Open in OneNote to open all OneNote notebooks that you want to convert, and ensure they are all fully synchronized before running the conversion. This applies to local OneNote notebooks and cloud OneNote notebooks (E.g. OneDrive or Microsoft Teams).

Q: Page attachments (files, images) are missing or corrupt during conversion

Cause: Possible page content bug.

A: Create a new section, copy pages into it, run the script again. See case, which is similar to this case.

Error: File ConvertOneNote2Markdown.ps1 cannot be loaded because running scripts is disabled on this system.

A: Windows disables Powershell (.ps1) scripts by default for security reasons. To allow running .ps1 scripts temporarily only for the current Powershell session, run:

Set-ExecutionPolicy Bypass -Scope Process -Force

Error: Error HRESULT E_FAIL has been returned from a call to a COM component

Cause: Powershell 7.1.x and above does not support loading Win32 GAC Assemblies.

Solution: Use a version of Powershell between 5.x and 7.0.x. See here.

Error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005(CO_E_SERVER_EXEC_FAILURE)

Cause: Mismatch in security contexts of Powershell and OneNote.

Solution: Ensure both Powershell and OneNote are run under the same user privileges. An easy way is to run both Powershell and OneNote as Administrator.

Error: Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope]

Cause: Mismatch in security contexts of Powershell and OneNote.

Solution: Ensure both Powershell and OneNote are run under the same user privileges. An easy way is to run both Powershell and OneNote as Administrator.

Error: Exception calling "Publish" with "4" argument(s): "Class not registered"

Cause: Microsoft Word is not installed.

Solution: Ensure Microsoft Word is installed.

Error: Exception: Exception calling "Publish" with "4" argument(s): "Server execution failed Server execution failed"

Cause: Microsoft Word plugin(s) causing publishing to .docx to fail. E.g. zotero plugin (see case).

Solution: Disable all Microsoft Word plugins before running the conversion.

Error: Exception: Exception calling "Publish" with "4" argument(s): "0x80042006"

Cause 1: Mismatch in security contexts of Powershell and OneNote.

Solution 1: Ensure both Powershell and OneNote are run under the same user privileges. An easy way is to run both Powershell and OneNote as Administrator.

Cause 2: $notesdestpath is not an absolute path.

Solution 2: Use an absolute path for $notesdestpath.

Error: Exception calling "Publish" with "4" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

Cause: Windows Defender could be blocking pandoc.exe. See case.

Solution: Disable Windows Defender. Click Start > Windows Security, under Virus and threat protection > Exclusions click Add or remove exclusions, click Add an exclusion and browse to C:\Program Files\Pandoc\pandoc.exe. Then retry the conversion.

If pandoc.exe is still blocked, you might try to turn off settings under Virus and threat protection, App and browser control, and Device Security.

Error: Exception calling "Publish" with "4" argument(s): "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"

Cause 1: OneNote is not open during the conversion.

Solution 1: Open OneNote and keep it open during the conversion.

Cause 2: : Page content bug.

Solution 2: Create a new section, copy pages into it, run the script again. See case.

Error: Convert-OneNotePage : Error while renaming image file name references to 'xxx.png: Illegal characters in path.

Cause: Windows Powershell ISE does not support long paths using the \\?\ prefix, e.g. \\?\C:\path\to.

Solution: Do not use Window Powershell ISE. Use Windows Powershell, or Powershell Core. See requirements.

Credits

convertonenote2markdown's People

Contributors

leojonathanoh avatar linzack avatar mikelehen avatar nixsee avatar sjoerdv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

convertonenote2markdown's Issues

Convert OneNote to Obsidian Markdown - What I did

See my other issue, #122 , but here is what I did to convert OneNote to Obsidian notes for reference. This took me hours and hours to troubleshoot so hopefully it will save everyone some time.

I followed the install instructions including using Choco to install but had to run the terminal as admin because the environmental variables didn't get set. Then BOTH visual studio code (run the script within that) AND OneNote need to be opened in Administrator mode. If I didn't run OneNote in administrator mode, it didn't work. For reference, I'm using OneNote 2016 Desktop version.

Now for the part that asks about the pandoc conversion strings, I used this one:
markdown-simple_tables-multiline_tables-grid_tables+pipe_tables-bracketed_spans+native_spans+startnum.

Then I also put to create a new doc file, save the doc files, etc, for troubleshooting. I also put in "255" as the max number of characters to export, not 32. However later I ran into a few files that were too large of file names to sync so had to manually remove them. Then I ran the script and it created the .md files.

You then have to go into Notepad++ or another editor and do mass find and replace across the entire directory. First of all there were some weird comments showing up, so I had to find/replace those to blank. Then I also did find/replace on all images that had appended after them something like {width:xx px, height: xxpx}. To replace those I did a regular expression search in Notepad++ across all the directories, and put in the .* as a wildcard, so {width:.* px, height: .*px}. You have to select regular expression as the search method, NOT case sensitive.

The pandoc conversion strings I listed above will create all underlined text as: **Text Here. However you need to create a separate CSS snippet for that: (See obsidian docs for how to create css snippets)

.underline {
    text-decoration: underline;
}

The other thing I had to find/replace was a ridiculous amount of blank space. So basically I did \n for 15 times: \n\n\n\n etc, and then replaced it with \n\n. Then I did find and replace. And then took off one \n (now 14 times) and did another find and replace. And so on. Time consuming but I didn't know another way of doing it.

I think that's it.

--markdown-headings=atx throws error

Bug

Pandoc throws unknown option error with --markdown-headings=atx

which causes failure to convert

Discussion

This is the default setting anyway, and the removal of this argument fixed the error for me

Environment

Output of Configuration

Configuration:
dryRun: 1
notesdestpath: c:\Users\user\Documents\OneDriveMigration
targetNotebook:
usedocx: 1
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 150
medialocation: 1
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

**Output of `$PSVersionTable`**

```powershell
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.25151.1000
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.25151.1000
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Images and tables are mangled in output

Images and tables are not coming through correctly in the output. Backslashes in image paths are missing so I end up getting output like this:

![](C:tempnotesNotebookmediaMyImage.png){width="12.840277777777779in" height="16.59027777777778in"}

But it should be C:\temp\notes\Notebook\media\MyImage.png

Also, tables are coming through as mangled HTML (no angle brackets) instead of markdown tables, e.g. I'm getting

tabletheadtr class="header"thh1 id="san-diego"San Diego/h1/ththh1 id="section"
/h1/ththh1 id="palm-springs"Palm Springs/h1/ththh1 id="section-1"
/h1/ththh1 id="sacramento"Sacramento/h1/ththh1 id="section-2"
...

instead of

| San Diego | Palm Springs |
...

Retrieving the COM class factory for component failed

I am running Win10 and Onenote 2016. Don't know what's causing this.

New-Object : Retrieving the COM class factory for component with CLSID {DC67E480-C3CB-49F8-8232-60B0C2056C8E} failed
due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\Users\ez\Downloads\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote
2MarkDown-v2.ps1:721 char:16
+     $OneNote = New-Object -ComObject OneNote.Application
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Users\ez\Downloads\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote2MarkDown4Obsidian-master\ConvertOneNote
2MarkDown-v2.ps1:724 char:5
+     $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hiera ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS-Error during conversion

Thank you so much for your script. It´s amazing to read and I´m looking forward to converts my great amount of Onenote Notes to Markdown!

Unfortunately its showing up some errors during conversion when I use the normal Powershell-Window (in Admin Mode):
New-Object : Die COM-Klassenfactory für die Komponente mit CLSID {DC67E480-C3CB-49F8-8232-60B0C2056C8E} konnte
aufgrund des folgenden Fehlers nicht abgerufen werden: 80080005 Starten des Servers fehlgeschlagen (Ausnahme von
HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
In D:\Users\afrei\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:353 Zeichen:16
$OneNote = New-Object -ComObject OneNote.Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In D:\Users\afrei\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:356 Zeichen:5
$OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hiera ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull

Ausnahme beim Aufrufen von "ReleaseComObject" mit 1 Argument(en): "Der Objektverweis wurde nicht auf eine
Objektinstanz festgelegt."
In D:\Users\afrei\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:398 Zeichen:5
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNo ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : NullReferenceException

Remove-Variable : Es kann keine Variable mit dem Namen "OneNote" gefunden werden.
In D:\Users\afrei\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:399 Zeichen:5
Remove-Variable OneNote
~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand

Thats the whole thing as screenshot:
powershell_CQPqxemxLT

Here some information about my system:

  • Windows 10 2004 (latest Updates from 10th September 2020 installed)
  • Onenote and Word Professional Plus 2016 (latest Updates from 10th September 2020 installed)
  • Cloned/downloaded the Master-Branch at 10th September 2020
  • used an absolute path
  • run Skript with default values (as show in the screenshot) AND with custom values (both gave out the same errors)
  • installed pandoc (verison 2.10.1) through chocolatey
  • installed recommended Onetastic Addin (Version 4.40 downloaded from the original Webpage)

keepspaces doesn't work with nested list items.

Bug

The $keepspaces=1 option ("Clear double spaces in bullets") only works for top-level list items, not nested list items.

Expectation

It should work for nested list items too.

Discussion

If you have a note like:
image

The generated markdown is:

-   List item 1

    -   Nested item 1

    -   Nested item 2
-   List item 2

But it should ideally be:

-   List item 1
    -   Nested item 1
    -   Nested item 2
-   List item 2

I'll send a PR that fixes this.

Environment

Output of Configuration

Configuration:
dryRun: 1
notesdestpath: d:\drive\docs\Obsidian\Life
targetNotebook: MigrationTest
usedocx: 1
keepdocx: 2
docxNamingConvention: 2
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 255
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1```

**Output of `$PSVersionTable`**

```powershell
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Feature: Filename and Folder Name use space instead of dash

After I import the md files into Joplin, I notice the note title and notebook name have dashes between words. Can you add option to allow the user to choose which format to use? Right now I have to use file rename app to rename the filename and folder name using space.

Doesn't export attachments in nested objects such as tables

Bug

Attachments in nested objects (such as tables) aren't exported. A common place where this occurs is when trying to export notes that were generated with Outlook's "Send To OneNote." In this case, all email attachments are put in the email header table and don't currently get exported.

Expectation

I would expect all attachments to be exported and linked to the output markdown file.

Discussion

The primary issue is that the powershell script does a shallow search for attachments, assuming they will all happen within the first layer of the XML file:

# Get any attachment(s) found in pages
if (Get-Member -InputObject $pagexml -Name 'Page') {
    if (Get-Member -InputObject $pagexml.Page -Name 'Outline') {
        $insertedFiles = $pagexml.Page.Outline.OEChildren.OE | Where-Object { $null -ne $_ -and (Get-Member -InputObject $_ -Name 'InsertedFile') } | ForEach-Object { $_.InsertedFile }
        foreach ($i in $insertedFiles) {
            $attachmentCfg = [ordered]@{}
            $attachmentCfg['object'] =  $i
            $attachmentCfg['nameCompat'] =  $i.preferredName | Remove-InvalidFileNameCharsInsertedFiles
            $attachmentCfg['markdownFileName'] =  $attachmentCfg['nameCompat'] | Encode-Markdown -Uri
            $attachmentCfg['source'] =  $i.pathCache
            $attachmentCfg['destination'] =  [io.path]::combine( $pageCfg['mediaPath'], $attachmentCfg['nameCompat'] )

            $attachmentCfg
        }
    }
}

A simple fix is to switch to an XPath-based search of the XML file:

$pagexml = Get-OneNotePageContent -OneNoteConnection $OneNoteConnection -PageId $pageCfg['object'].ID

$ns = new-object Xml.XmlNamespaceManager $pagexml.NameTable
$ns.AddNamespace("one", $pagexml.DocumentElement.NamespaceURI)
$insertedFiles = $pagexml.SelectNodes("//one:InsertedFile", $ns)
foreach ($i in $insertedFiles) {
    $attachmentCfg = [ordered]@{}
    $attachmentCfg['object'] =  $i
    $attachmentCfg['nameCompat'] =  $i.preferredName | Remove-InvalidFileNameCharsInsertedFiles
    $attachmentCfg['markdownFileName'] =  $attachmentCfg['nameCompat'] | Encode-Markdown -Uri
    $attachmentCfg['source'] =  $i.pathCache
    $attachmentCfg['destination'] =  [io.path]::combine( $pageCfg['mediaPath'], $attachmentCfg['nameCompat'] )

    $attachmentCfg
}

This has the added benefit of removing the nested condition statement. This method has been tested and seems to fix the issue.

Environment

Output of Configuration

For example:

Configuration:
$dryRun = 1
$notesdestpath = 'c:\tmp\notes'
$targetNotebook = ''
$usedocx = 1
$keepdocx = 2
$docxNamingConvention = 2
$prefixFolders = 1
$mdFileNameAndFolderNameMaxLength = 100
$medialocation = 2
$conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
$headerTimestampEnabled = 1
$keepspaces = 1
$keepescape = 1
$newlineCharacter = 1
$exportPdf = 1

Output of $PSVersionTable

For example:

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

First line of note can be omitted depending on text box position

Bug

In OneNote by default there seems to be a small gap (1 line of text high) between the heading and the textbox. But if you drag a page's text box up to be directly under the header, then the first line of text in the text box won't be included in the exported markdown.

Expectation

All lines of text in your notes should be included.

Discussion

I inadvertently had at least one note where the text box was directly below the header, like this (no idea why):
image

The exported docx file looks like this:
image

A "good" note looks like this:
image

And the exported docx looks like this:
image

Note there is a blank line between the header and the note contents. It turns out that if that blank line is not there, then the first line of text will be discarded. I believe this is due to the "Add heading" mutation which deletes everything up until the first line break when adding the heading.

searchRegex = '^[^\r\n]*'

I don't quite understand why the regex is currently ^[^\r\n]* but I think changing it to ^\s* might solve the issue. I'll send a PR.

Environment

Output of Configuration

dryRun: 1
notesdestpath: d:\drive\docs\Obsidian\Life
targetNotebook: MigrationTest
usedocx: 1
keepdocx: 2
docxNamingConvention: 2
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 255
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

For example:

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Errors in both files

Hello,

I am having problems with both of these files. Onetastic says it "failed to read" the xml file when I tried to import it.
When running the script in Powershell, it tells me it cannot use the ampersand:

PS C:\Users\bmwhi\Downloads> .\ConvertOneNote2MarkDown-v2.ps1
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:187 char:23

  •               Sign&nbsp;up
    
  •                   ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:215 char:189

  • ... ata-ga-click="(Logged out) Header, go to Features">Features <span cla ...
  •                                                             ~
    

The '<' operator is reserved for future use.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:215 char:269

  • ... nk-symbol float-right text-normal color-text-tertiary pr-3">→</s ...
  •                                                             ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:217 char:165

  • ... ck Link--secondary no-underline f5 Bump-link--hover">Mobile <span cla ...
  •                                                             ~
    

The '<' operator is reserved for future use.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:217 char:245

  • ... nk-symbol float-right text-normal color-text-tertiary pr-3">→</s ...
  •                                                             ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:218 char:176

  • ... k Link--secondary no-underline f5 Bump-link--hover">Actions <span cla ...
  •                                                             ~
    

The '<' operator is reserved for future use.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:218 char:256

  • ... nk-symbol float-right text-normal color-text-tertiary pr-3">→</s ...
  •                                                             ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:219 char:182

  • ... ink--secondary no-underline f5 Bump-link--hover">Codespaces <span cla ...
  •                                                             ~
    

The '<' operator is reserved for future use.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:219 char:262

  • ... nk-symbol float-right text-normal color-text-tertiary pr-3">→</s ...
  •                                                             ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\bmwhi\Downloads\ConvertOneNote2MarkDown-v2.ps1:220 char:178

  • ... Link--secondary no-underline f5 Bump-link--hover">Packages <span cla ...
  •                                                             ~
    

The '<' operator is reserved for future use.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : AmpersandNotAllowed

Onetastic is probably not such a big deal since I don't use expanded paragraphs, but the script itself is not working at all.

Please help!

Errors and only getting word files (no md)

I have no idea what I'm doing wrong (it's the first I've used Onetastic and Pandoc, and probably the first time I've run a script like this on Powershell) but I followed the instructions (including opening both powershell and OneNote on administrator and running the security bypass) and tried it a few times and the results are the same. I have almost no coding knowledge and googling what might work to fix it hasn't worked out (I initially had spaces in one of the folders and did both CD "" and just straight up removing the spaces in the folder name to navigate to the proper folders, but beyond that I couldn't figure out what still needed to be done).

Below is an example of the error I got (it seems to have happened with every OneNote page):

REDACTED Troubleshooting OneNote to Obsidian conversion 1

REDACTED Troubleshooting OneNote to Obsidian conversion 2

Not sure what information would be relevant but I have the copy of this repository saved in Desktop\ProgramsAndOtherInstalls and the folder I wanted the .md files to go to is Documents\OneNoteExport2Obsidian. Within the later folder the script made a folder for each notebook I had on OneNote (the page "Prologue" is from my OneNote notebook "recover") and within those are three folders: "docx" where the .docx files of all my OneNote pages were stored, and two folders named after the main sections I have in my "recover" notebook. Those two sections have folders that correspond to their subsections but all the folders are empty except for one document I had saved into one of my OneNote pages.

Just in case this was important, the options I chose were the following:
REDACTED Troubleshooting OneNote to Obsidian conversion 3

Attached files not inside an outline aren't included.

Bug

File attachments in a OneNote page that aren't in an outline (text block) do not get imported into media/ or linked from the generated markdown.

Expectation

All file attachments should be imported.

Discussion

If you drag/drop a file into a OneNote page but don't put it inside of a text block (I guess OneNote calls this an "outline"?) then it won't be included. E.g.:
image

When I import this I get the following markdown:

<<[testing.txt](media/testing.txt)>>



<<testing2.txt>>



<<testing3.txt>>

Note that testing2.txt and testing3.txt are not properly linked.

I see that the existing code

$insertedFiles = $pagexml.Page.Outline.OEChildren.OE | Where-Object { $null -ne $_ -and (Get-Member -InputObject $_ -Name 'InsertedFile') } | ForEach-Object { $_.InsertedFile }
is looking at $pagexml.Page.Outline.OEChildren.OE but it looks like these extra files end up in $pagexml.Page.InsertedFile instead.

I will provide a PR that attempts to address this.

Environment

dryRun: 1
notesdestpath: d:\drive\docs\Obsidian\Life
targetNotebook: MigrationTest
usedocx: 1
keepdocx: 2
docxNamingConvention: 2
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 255
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

UTF8 Issue

I used all 6 coding methods but non of the could handle the UTF8 coding.
Teh DOCX-Files where okay, but the step to the MDfiles killed the special characters like ä,ö,ü etc.

Is there a way to fix that?

Obsidian Image Problems

I actually don't know if I should put it as a bug or a feature. I'm using this tool to convert onenote to md for obsidian. Since the owner of this repository also recommended obsidian, I believe we are using it for the same reason...

Bug

The images in the successfully converted md files look like this

![Machine generated alternative text: xxx ](media/单弦谱_Happy-birthday-image1.png){width="7.9375in" height="4.645833333333333in"}

But this is not the image format that Obsidian would accept. Obsidian accept image format as below, in which the numbers represent pixels.

![Machine generated alternative text: xxx |793x464](media/单弦谱_Happy-birthday-image1.png)

Expectation

Images are sized correctly.

Discussion

So now the images look like this in Obsidian
screenshot of Obsidian

Environment

Output of Configuration

Configuration:
dryRun: 0
notesdestpath: C:\Users\verac\OneDrive\Documents\Notebooks
targetNotebook:
usedocx: 2
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 200
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 2
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.13
PSEdition                      Core
GitCommitId                    7.0.13
OS                             Microsoft Windows 10.0.22622
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The variable '$pageConversionConfigs' cannot be retrieved because it has not been set

Bug

When I try to run the script, the console returns: The variable '$pageConversionConfigs' cannot be retrieved because it has not been set.

Expectation

Either success on converting the notebook or an informed log about what has gone wrong

Discussion

Hi! I love this app. Sadly I cannot make it work, When I run the script, I have this response from the shell, (after the config log):

Notebooks to convert:
Auca's Notebook

Converting notebook 'Auca's Notebook'... (Ignoring deleted notes)

Building conversion configuration for Auca's Notebook [Notebook]
Ignoring empty Section Group:
Convert-OneNote2MarkDown : The variable '$pageConversionConfigs' cannot be retrieved because it has not been set.
At C:\Users\aucac\other-repos\ConvertOneNote2markdown\ConvertOneNote2MarkDown-v2.ps1:1474 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at Convert-OneNote2MarkDown, C:\Users\aucac\other-repos\ConvertOneNote2markdown\ConvertOneNote2MarkDown-v2.ps1: line 1436
at <ScriptBlock>, C:\Users\aucac\other-repos\ConvertOneNote2markdown\ConvertOneNote2MarkDown-v2.ps1: line 1474
at <ScriptBlock>, <No file>: line 1
At C:\Users\aucac\other-repos\ConvertOneNote2markdown\ConvertOneNote2MarkDown-v2.ps1:1474 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Cleaning up...
Exiting.

The script recognizes perfectly all my notebooks in onenote, but from there goes no further.

These are the setps I took:

  1. I cloned the repo
  2. installed pandoc with choco install pandoc
  3. renamed config file to config.ps1
  4. ran .\ConvertOneNote2MarkDown-v2.ps1

I googled about the error and found this about a policy, tried, and didn't work either.
Am I doing something wrong? I also tested alopezrivera/owo but got the same result.

Environment

Output of Configuration

Configuration:
dryRun: 1
notesdestpath: c:\temp\notes
targetNotebook:
usedocx: 1
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 32
medialocation: 1
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

When converting page with images, there's a line of text with width and height, which shouldn't be displayed?

Bug

After conversion, when I opened the page with images, under each image, there's a line of text like {width="12.072916666666666in" height="6.65625in"}. It appears under every single image.

Expectation

I don't think there should be such text under the images. I've got notes with lots of images, and it's annoying to have to delete the text manually.

Discussion

This is my first time using it and everything else seems to have converted correctly.

Environment

Output of Configuration

$dryRun = 0
$notesdestpath = 'c:\tmp\notes'
$targetNotebook = ''
$usedocx = 1
$keepdocx = 1
$docxNamingConvention = 2
$prefixFolders = 1
$mdFileNameAndFolderNameMaxLength = 128
$medialocation = 1
$conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
$headerTimestampEnabled = 2
$keepspaces = 1
$keepescape = 1
$newlineCharacter = 1
$exportPdf = 1
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

If I leave Onenote open it dosen't work

If I leave OneNote open I getting the following error:

New-Object : Retrieving the COM class factory for component with CLSID {DC67E480-C3CB-49F8-8232-60B0C2056C8E} failed
due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:357 char:16
+     $OneNote = New-Object -ComObject OneNote.Application
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:360 char:5
+     $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hiera ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:438 char:5
+     [System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNo ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

Remove-Variable : Cannot find a variable with the name 'OneNote'.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:439 char:5
+     Remove-Variable OneNote
+     ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand

`^M` characters in section names intead of `+`

Bug

^M characters in section names

Expectation

+ character in section names

Discussion

Seems like a bug in the OneNote API. This strange behavior most likely only affects section / section group names, and does not affect page names. So a page named C++ notes will retain the + symbol in the final markdown file name.

If one had a section named C++, the section object .name value is C^M^M. But if one had a page called C++ notes, the page object .name retains +. Example $section.outerXml:

<one:Section name="C^M^M" ID="{E2E817CC-5E28-4C1F-A35F-961FCB94C8CE}{1}{B0}" path="https://d.docs.live.net/0123456789abcdef/Skydrive Notebooks/mynotebook/C^M^M.one" lastModifiedTime="2017-10-05T13:16:39.000Z" color="#ADE792" isUnread="true" xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote">
    <one:Page ID="{E2E817CC-5E28-4C1F-A35F-961FCB94C8CE}{1}{E1946944932425511829941980548791903311361351}" name="C++ notes" dateTime="2016-06-06T01:41:22.000Z" lastModifiedTime="2016-06-06T01:41:27.000Z" pageLevel="1" />
</one:Section>

Workaround

Since only section names are affected, a user can easily rename their folders with ^M manually as a temporary quick workaround.

Tables

Hi,

When using the script, whatever type of MD I select my OneNote tables are not well migrated to MD tables.

For example a OneNote table:
image

The same table (part of) but in Obsidian / Markdown:

image

OneNoteConnection error

Bug

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope]

Output:

Convert-OneNote2MarkDown : Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
At D:\Nie-gry\OnenoteToObsidian\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at Get-OneNoteHierarchy, D:\Nie-gry\OnenoteToObsidian\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line 568
at Convert-OneNote2MarkDown, D:\Nie-gry\OnenoteToObsidian\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line 1362
at <ScriptBlock>, D:\Nie-gry\OnenoteToObsidian\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line 1423
at <ScriptBlock>, <No file>: line 1
At D:\Nie-gry\OnenoteToObsidian\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Cleaning up...
Exiting.

Expectation

Execute properly.

Discussion

Script starts, writes up configuration (read config example and edited properties)

  • Backed up all my Notes from OneNote dir (standard one, appdata/local)
  • made up my config
  • tried to run script without Pandoc installed which obviously resulted errors
  • downloaded and installed Pandoc, checked versions of win and onenote + word
  • checked Pandoc (cmd pandoc.exe runs properly)
  • rebooted pc
  • error as above

It may be important - I'm running script from VSC powershell, it shouldn't make any troubles, right?

Environment

Win10 Home x64 21H2

OneNote 2016 from Office Professional Plus 2019 (somehow)
16.0.10382.20034, version 1808, compilation 10382.20034 quick-installation

Word 2016 from Office Professional Plus 2019
16.0.10382.20034, version 1808, compilation 10382.20034 quick-installation (same as onenote)

Pandoc 2.17.1.1 (.msi installer, hope it installed properly)

Output of Configuration

Configuration:
dryRun: 1
notesdestpath: D:\Nie-gry\converted_notes
targetNotebook: 
usedocx: 1
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 2
mdFileNameAndFolderNameMaxLength: 128
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 2
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Add Created/Modify Date to files & folders

Current

I am working on exporting my journals from Onenote to md to be used in Obsidian. In OneNote my structure was like:
Year (folder)

  • Month (folder)
    • journal entry (1st of month) (file)
    • journal entry (2ed of month) (file)
      ...

The export works fine, but the Date Created/Date modified of the files/folders in Windows is from when the script created the files. Thus, when I try to import things into Obsidian, the journals are chronologically out of order.

Expectation

I think this could be solved two ways. If you modified the script to update the actual file /folder with the Created/modified date, that would fix the order. These dates seemed to be collected while converting:

Created: 2021-12-06 08:53:59 -0600

Modified: 2021-12-07 08:36:58 -0600

By updating the files/folders with these dates, that would fix the order.

Second option would be to try and force the script to process things chronological order, that way the created/modified dates would at least be in order. But that might be harder to implement.

Error when running

Bug

Error:

Convert-OneNote2MarkDown : Retrieving the COM class factory for component with CLSID
{DC67E480-C3CB-49F8-8232-60B0C2056C8E} failed due to the following error: 80080005 Server execution failed (Exception
from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown-v2.ps1:1423 char:5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at New-OneNoteConnection, C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown-v2.ps1: line
530
at Convert-OneNote2MarkDown, C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown-v2.ps1: line 1359
at , C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown-v2.ps1: line 1423
at , : line 1
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown-v2.ps1:1423 char:5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Expectation

No error.

Discussion

After running for a minute.

Environment

Windows 10 Version = 20H2 Build 19042.1288
OneNote version = 1808 (Msft office Professional Plus 2019)
Pandoc Version = 2.16.2

Output of Configuration

For example:

Configuration:
dryRun: 1
notesdestpath: C:\Users\edugoliv\Downloads\onmd
targetNotebook:
usedocx: 1
keepdocx: 2
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 32
medialocation: 1
conversion: markdown_mmd-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

For example:

Name Value


PSVersion 5.1.19041.1237
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1237
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].

Run new office onenote with admin permissions and powershell with admin permissions
Version Windows 10 Pro
Version 20H2
Compilation 19042.631

Error Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
At C:\GIT\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:357 char:31
... erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (Microsoft.Offic....HierarchyScope:TypeName) [], RuntimeException
FullyQualifiedErrorId : TypeNotFound

Add unit tests

Current

No unit tests.

Expectation

Unit tests.

Discussion

Currently the code is slightly fragile from briefly scanning it, because it was contributed by previous multiple authors who did not include unit tests. New MRs might accidentally break some behavior. Hence unit tests ought to be added.

Minor refactor of code to be in smaller functions might be necessary as part of this implementation.

Conversion fails with what appears to be a COM related error message

Bug

Conversion fails with what appears to be a COM related error message.

Expectation

I expected my dry run to go to completion.

Discussion

The following is the output of the tool when I ran it:

Configuration:
dryRun: 2
notesdestpath: C:\Md
targetNotebook:
usedocx: 1
keepdocx: 1
docxNamingConvention: 2
prefixFolders: 2
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 2
keepescape: 1
newlineCharacter: 1
Convert-OneNote2MarkDown : Retrieving the COM class factory for component with CLSID
{DC67E480-C3CB-49F8-8232-60B0C2056C8E} failed due to the following error: 80080005 Server execution failed (Exception
from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
At C:\Src\ConvertOneNoteToMarkdown\ConvertOneNote2MarkDown-v2.ps1:1373 char:5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at New-OneNoteConnection, C:\Src\ConvertOneNoteToMarkdown\ConvertOneNote2MarkDown-v2.ps1:
line 510
at Convert-OneNote2MarkDown, C:\Src\ConvertOneNoteToMarkdown\ConvertOneNote2MarkDown-v2.ps1: line 1309
at , C:\Src\ConvertOneNoteToMarkdown\ConvertOneNote2MarkDown-v2.ps1: line 1373
at , : line 1
At C:\Src\ConvertOneNoteToMarkdown\ConvertOneNote2MarkDown-v2.ps1:1373 char:5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Cleaning up...
Exiting.

Environment

Output of Configuration

(see above)

Output of $PSVersionTable

For example:

Name                           Value
----                           -----
PSVersion                      5.1.19041.1151
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1151
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Exception calling "GetHierarchy" with "3" argument(s)

Bug

Script finishes with error message.

Discussion

VERBOSE: The object written to the pipeline is an instance of the type
"Microsoft.Office.Interop.OneNote.Application2Class" from the component's primary interoperability assembly. If this
type exposes different members than the IDispatch members, scripts that are written to work with this object might not
work if the primary interoperability assembly is not installed.
Convert-OneNote2MarkDown : Exception calling "GetHierarchy" with "3" argument(s): "Unable to cast COM object of type
'Microsoft.Office.Interop.OneNote.Application2Class' to interface type
'Microsoft.Office.Interop.OneNote.IApplicationCOM'. This operation failed because the QueryInterface call on the COM
component for the interface with IID '{452AC71A-B655-4967-A208-A4CC39DD7949}' failed due to the following error:
Interface not registered (Exception from HRESULT: 0x80040155)."
At C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:1373 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at Get-OneNoteHierarchy,
C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 548
at Convert-OneNote2MarkDown, C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line
1312
at <ScriptBlock>, C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 1373
at <ScriptBlock>, <No file>: line 1
At C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:1373 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Environment

Windows Surface Pro 6
Windows 10
Office 2019 Professional Plus
Word, OneNote and Powershell open in admin mode
Security Scope Bypass already done

Errors all over the place

Hi, by following the steps I encounter errors and just can't make it work.

Error while renaming image file path references for file 'AD': You cannot call a method on a null-valued expression.
##### My Article Name.
Error while publishing file 'My Article Name.' to docx: Exception calling "Publish" with "4" argument(s): "**The RPC server is unavailable**. (Exception from HRESULT: 0x800706BA)"
pandoc.exe: C:\MD\My Article\docx\My Article Name-&-Services..docx: openBinaryFile: does not exist (No such file or directory)
Exception calling "GetPageContent" with "3" argument(s): "The RPC server is unavailable. (Exception from HRESULT:
0x800706BA)"
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:174 char:13
+             $OneNote.GetPageContent($pageid, [ref]$pagexml, 7)
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException

Get-Content : Cannot find path
'C:\MD\My Article\Technologies\mytech\subtech\My Article Name-&-Services..md' because
it does not exist.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:200 char:21
+ ...       $orig = Get-Content -path "$($fullfilepathwithoutextension).md"
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\MD\My Article...-&-Services..md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Cannot index into a null array.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:201 char:29
+             $orig[0] = "# $($page.name)"
+                             ~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:207 char:34
+ ...            Set-Content -Path "$($fullfilepathwithoutextension).md" -V ...
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Get-Content : Cannot find path
'C:\MD\My Article\Technologies\mytech\subtech\My Article Name-&-Services..md' because
it does not exist.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:215 char:23
+ ...           ((Get-Content -path "$($fullfilepathwithoutextension).md" - ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\MD\My Article-...-&-Services..md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while clearing double spaces from file 'C:\MD\My Article\Technologies\mytech\subtech\My Article Name-&-Services.' : You cannot call a method on a null-valued expression.
Get-Content : Cannot find path
'C:\MD\My Article\Technologies\mytech\subtech\My Article Name-&-Services..md' because
it does not exist.
At C:\temp\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:249 char:19
+ ...           ((Get-Content -path "$($fullfilepathwithoutextension).md" - ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\MD\My Article-...-&-Services..md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming file references - Illegal characters in path

Bug

During conversion, it fails to rename the reference of each image found.
It successfully creates & moves the images, but when renaming the references in markdown, the script fails for EVERY picture. (drawings as well)

Expectation

Renaming the file references should work, considering the files were moved properly.

Discussion

I renamed my username and the name of the Notebook for privacy purposes. The format stayed the same though, just used a different name for both.

Here is a sample output of the script: (it throws a lot of errors because of the amount of images)

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image7.png to C:\Users
\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image7.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image7.png', Replacement: 'Chemie-image7.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image7.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image70.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image70.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image70.png', Replacement: 'Chemie-image70.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image70.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image71.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image71.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image71.png', Replacement: 'Chemie-image71.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image71.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

VERBOSE: Moving image: C:\Users\user\AppData\Local\Temp\My-Notebook\2022-03-01-00-17-57-5426867\media\image72.png to C:\User
s\user\Desktop\tmp\My-Notebook\Allgemeines---Globale-Themen\Vorbereitung-Reihungstest\media\Chemie-image72.png
VERBOSE: Mutation of markdown: Rename image references to unique name. Find 'image72.png', Replacement: 'Chemie-image72.png'
Convert-OneNotePage : Error while renaming image file name references to 'Chemie-image72.png: Illegal characters in path.
At D:\#Git-Stash\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1387 char:257

+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
  + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is a sample from the converted markdown file, containing a reference, which can't be renamed:

Chemie

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image1.png){width="0.8125in" height="1.2708333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image2.png){width="0.8611111111111112in" height="1.2569444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image3.png){width="0.9375in" height="0.7569444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image4.png){width="0.8819444444444444in" height="1.0416666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image5.png){width="0.9375in" height="1.0833333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image6.png){width="0.8611111111111112in" height="1.0in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image7.png){width="0.7986111111111112in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image8.png){width="0.8819444444444444in" height="1.0347222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image9.png){width="0.8194444444444444in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image10.png){width="0.875in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image11.png){width="1.0in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image12.png){width="0.875in" height="0.9583333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image13.png){width="0.8125in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image14.png){width="0.875in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image15.png){width="1.0347222222222223in" height="0.9027777777777778in"}

Saturday, 29 February 2020

14:49

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image16.png){width="0.9027777777777778in" height="1.0833333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image17.png){width="0.875in" height="1.125in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image18.png){width="1.4583333333333333in" height="1.4722222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image19.png){width="0.7708333333333334in" height="1.0in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image20.png){width="0.8194444444444444in" height="1.1041666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image21.png){width="0.9236111111111112in" height="1.0416666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image22.png){width="0.8402777777777778in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image23.png){width="0.8958333333333334in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image24.png){width="0.8611111111111112in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image25.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image26.png){width="0.8333333333333334in" height="0.8541666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image27.png){width="0.9236111111111112in" height="0.8958333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image28.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image29.png){width="0.8194444444444444in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image30.png){width="0.9027777777777778in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image31.png){width="2.5in" height="1.8263888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image32.png){width="0.8125in" height="0.8333333333333334in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image33.png){width="1.6875in" height="1.6875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image34.png){width="1.0833333333333333in" height="1.4930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image35.png){width="1.4375in" height="1.625in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image36.png){width="5.25in" height="5.493055555555555in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image37.png){width="0.3958333333333333in" height="5.555555555555555in"}

<https://www.youtube.com/watch?v=J2KJRRH0E3Y>

 

<https://www.youtube.com/watch?v=f5-W87IGLFY>

 

simpleClub =\> Youtube

![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image38.png){width="1.2708333333333333in" height="1.4722222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image39.png){width="0.4444444444444444in" height="0.5763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image40.png){width="0.4375in" height="0.5763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image41.png){width="0.4236111111111111in" height="0.5486111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image42.png){width="1.0in" height="1.3680555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image43.png){width="0.3333333333333333in" height="0.4444444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image44.png){width="0.75in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image45.png){width="1.0208333333333333in" height="1.2916666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image46.png){width="0.7569444444444444in" height="1.1666666666666667in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image47.png){width="0.7430555555555556in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image48.png){width="0.8125in" height="1.25in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image49.png){width="0.7986111111111112in" height="1.3263888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image50.png){width="0.8541666666666666in" height="1.375in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image51.png){width="0.9236111111111112in" height="1.2083333333333333in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image52.png){width="1.0833333333333333in" height="1.875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image53.png){width="0.9930555555555556in" height="0.7916666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image54.png){width="0.8958333333333334in" height="0.9513888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image55.png){width="0.8333333333333334in" height="1.0138888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image56.png){width="0.5486111111111112in" height="0.6666666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image57.png){width="0.8819444444444444in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image58.png){width="0.9236111111111112in" height="0.75in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image59.png){width="0.8958333333333334in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image60.png){width="0.8194444444444444in" height="0.9027777777777778in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image61.png){width="0.9722222222222222in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image62.png){width="0.8125in" height="0.9722222222222222in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image63.png){width="0.8611111111111112in" height="0.9375in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image64.png){width="0.7777777777777778in" height="0.9166666666666666in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image65.png){width="0.8402777777777778in" height="0.8402777777777778in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image66.png){width="0.875in" height="0.9236111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image67.png){width="0.8819444444444444in" height="1.1319444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image68.png){width="0.8958333333333334in" height="0.8819444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image69.png){width="0.8541666666666666in" height="1.0763888888888888in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image70.png){width="0.9166666666666666in" height="1.1944444444444444in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image71.png){width="0.8402777777777778in" height="1.0625in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image72.png){width="0.9027777777777778in" height="0.9930555555555556in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image73.png){width="1.2291666666666667in" height="1.0347222222222223in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image74.png){width="0.8611111111111112in" height="1.2986111111111112in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image75.png){width="3.5625in" height="1.875in"}![](C:/Users/user/AppData/Local/Temp/My-Notebook/2022-03-01-00-17-57-5426867/media/image76.png){width="0.875in" height="1.1736111111111112in"}

Erdöl

Einheiten

Bindungen

Säuren & Basen (PH-Wert)

Environment

Windows 11 Pro - 10.0.22000
I ran the script as administrator inside ISE and also ran OneNote (Office-Version) as Administrator

Aside from the images & drawings, the conversion works well.

Output of Configuration

For example:

$dryRun = 1
$notesdestpath = 'C:\Users\user\Desktop\tmp'
$targetNotebook = 'My Notebook'
$usedocx = 1
$keepdocx = 1
$docxNamingConvention = 2
$prefixFolders = 1
$mdFileNameAndFolderNameMaxLength = 32
$medialocation = 2
$conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
$headerTimestampEnabled = 1
$keepspaces = 1
$keepescape = 1
$newlineCharacter = 1
$exportPdf = 2

Output of $PSVersionTable

For example:

PS > $PSVersionTable
Name                           Value                                                                                        
----                           -----                                                                                        
PSVersion                      5.1.22000.282                                                                                
PSEdition                      Desktop                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                      
BuildVersion                   10.0.22000.282                                                                               
CLRVersion                     4.0.30319.42000                                                                              
WSManStackVersion              3.0                                                                                          
PSRemotingProtocolVersion      2.3                                                                                          
SerializationVersion           1.1.0.1 

Unknown option --markdown-headings

I have one notebook open that I try to convert to Obsidian-flavored markdown, hence markdown (Pandoc). I have installed the Expand all Paragraphs macro and run it on the notebook. I use Windows 10, Microsoft OneNote 2016, Word 2016 and have pandoc installed - I believe the most recent version.

The folder structure is created successfully, however all of the folders are empty. There are many error messages, however they seem to always start with "Unknown option --markdown-headings" and then tripple down.

Use declarative configuration

Current

Interactive configuration.

Expectation

Declarative configuration

Discussion

This is a potentially breaking UX change, and some users might have to learn how to edit the script correctly.

Vote

In case of any readers who might prefer declarative configuration (I would vote for it), please vote for this feature via thumbs up, so I know that it's something that might actually be used. Or else I would consider the interactive configuration as generally more preferred.

Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.

Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\GIT\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1:352 char:21
if (Test-Path -Path $notesdestpath) {
~~~~~~~~~~~~~~
CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

Ordered list

Bug

Ordered lists from onenote have double spaces after conversion. When looking at the intermediate created doc files, it seems that there is a break after each line. I tried but I have no idea how to solve this. See image:

  1. Onenote:
    image

  2. Intermediate DOCX:
    image
    image

  3. Markdown output:
    image

I have not currently found a way to solve this, and it seems to me that I will have to change all ordered lists to bullet lists before doing the conversion. Is there any way this can be solved so that the lists don't have spaces?

Thanks

"Could not locate pandoc.exe. Please ensure pandoc is installed."

Hello,

I have installed pandoc (C:\Program Files\Pandoc\pandoc.exe) + antivrus disabled + set-ExecutionPolicy -ExecutionPolicy Unrestricted, but I have this error message:

PS C:\Windows\System32\ConvertOneNote2MarkDown> .\ConvertOneNote2MarkDown-v2.ps1
Get-Command : Le terme «pandoc.exe» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou
programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès
est correct et réessayez.
Au caractère C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:27 : 12

  • if (! (Get-Command -Name 'pandoc.exe') ) {
    
  •        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (pandoc.exe:String) [Get-Command], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

Convert-OneNote2MarkDown : Could not locate pandoc.exe. Please ensure pandoc is installed.
Au caractère C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1428 : 5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : à Validate-Dependencies,
C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1 : ligne 28
à Convert-OneNote2MarkDown, C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1 : ligne 1355
à , C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1 : ligne 1428
à , : ligne 1
Au caractère C:\Windows\System32\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1428 : 5

  • Convert-OneNote2MarkDown @params
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Cleaning up...
Exiting.

Thx!

Com error E_FAIL during call to Get-OneNoteHierarchy

Bug

When attempting to run this converter I get a Com error during call to Get-OneNoteHierarchy.

Environment

Configuration:
dryRun: 2
notesdestpath: c:\dev\notes
targetNotebook: PersonalNotebook
usedocx: 2
keepdocx: 2
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 64
medialocation: 1
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

OneNote bug? - Exception calling "Publish" with "4" argument(s): "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

Bug

Process halts and returns error. See: CovertOneNote2MarkDown.error.log

Expectation

Successful export

Discussion

  • Many pages successfully converted before failure
  • Attempting to export manually through the OneNote UI results in an app crash, thus possible OneNote bug
  • Reproduced with two different OneNote pages in different Notebooks
  • Both pages contained only images
  • Dryrun ran successfully
  • Expand all Paragraphs in Notebook.xml ran prior

Environment

Fairly recent re-install of Windows 10 Pro, Office installed with 365 license and unused prior to conversion effort.
Windows 10 Pro Version 21H1 (OS Build 19043.1348)
OneNote for Microsoft 365 MSO (Version 2111 Build 16.0.14701.20206) 64-bit

$dryRun = 1
$notesdestpath = 'c:\temp\work\notes'
$targetNotebook = 'Ryan @ Quantworks'
$usedocx = 1
$keepdocx = 2
$docxNamingConvention = 1
$prefixFolders = 1
$mdFileNameAndFolderNameMaxLength = 128
$medialocation = 1
$conversion = 'markdown-simple_tables-multiline_tables-grid_tables+pipe_tables'
$headerTimestampEnabled = 1
$keepspaces = 1
$keepescape = 1
$newlineCharacter = 1
$exportPdf = 1
Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Next steps for debugging

  1. Isolate page into separate notebook for testing
  2. Add text to page
  3. Reproduce on another Windows installation

Multiple 'being used by another process' errors

Errors while: 'renaming image file path references', 'set-content', 'while clearing double spaces', etc.

An example:
Error while renaming image file name references to 'image59.png' for file 'Note Name': The process cannot access the file 'D:\folder\Note Name.md' because it is being used by another process.

Error HRESULT E_FAIL has been returned from a call to a COM component.

Bug

The code gives an error at line 570

[xml]$hierarchy = ""
$OneNoteConnection.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, [ref]$hierarchy)

with the error saying "Error HRESULT E_FAIL has been returned from a call to a COM component."

Environment

Output of Configuration

Configuration:
dryRun: 0
notesdestpath: C:\00 OnenoteLocal\learning notes
targetNotebook:
usedocx: 2
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 200
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_ta
bles
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 2
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.22622
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Export fails with RPC error

Bug

A full export fails thowing an error "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"

Expectation

The export should complete successfully with no errors.

Discussion

Here is the full text of the errors:

## Providence cottage [Page]
Markdown file ready: c:\temp\notes\Andrew's-Notebook\Other\Providence-cottage.md
## Building conversion configuration for Salt pig menu [Page]
## Salt pig menu [Page]
Failed to convert page: Other\Salt-pig-menu. Exception: Error while publishing page to docx file c:\temp\notes\Andrew's-Notebook\docx\{E811580D-52F3-49D5-8033-A6469162AAE8}{1}{E19556216757004340579819475108420806793716133}-1650030024.docx. Exception: Exception calling "Publish" with "4" argument(s): "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"
Convert-OneNotePage : Failed to convert page: Other\Salt-pig-menu. Exception: Error while publishing page to docx file
c:\temp\notes\Andrew's-Notebook\docx\{E811580D-52F3-49D5-8033-A6469162AAE8}{1}{E195562167570043405798194751084208067937
16133}-1650030024.docx. Exception: Exception calling "Publish" with "4" argument(s): "The remote procedure call
failed. (Exception from HRESULT: 0x800706BE)"
At C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps
1:1387 char:257
+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage

## Building conversion configuration for GitHub - aladine/EverOrg: Evernote to Org mode migration tool [Page]
Convert-OneNote2MarkDown : Exception calling "GetPageContent" with "3" argument(s): "The RPC server is unavailable.
(Exception from HRESULT: 0x800706BA)"
At C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps
1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Convert-OneNote2MarkDown : at Get-OneNotePageContent,
at <ScriptBlock>,
C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps1:
line 865
at New-SectionGroupConversionConfig,
C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps1:
line 864
at Convert-OneNote2MarkDown,
C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps1:
line 1387
at <ScriptBlock>,
C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps1:
line 1423
at <ScriptBlock>, <No file>: line 1
At C:\Users\agab3\Downloads\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-2.18.1\ConvertOneNote2MarkDown-v2.ps
1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Cleaning up...
Conversion errors:
Failed to convert page: Other\Salt-pig-menu. Exception: Error while publishing page to docx file c:\temp\notes\Andrew's-Notebook\docx\{E811580D-52F3-49D5-8033-A6469162AAE8}{1}{E19556216757004340579819475108420806793716133}-1650030024.docx. Exception: Exception calling "Publish" with "4" argument(s): "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"
Exiting.

Environment

Output of Configuration

Export executed with all defaults (ENTER pressed at each prompt)

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Select specific sections or pages for convertion.

Current

Currently, the convertion will always happen to the entire notebook.

Expectation

Select specific sections or pages in the notebook for convertion.

Discussion

Is there any way to make the convertion happen to only part of the selected notebook, such as a several sections of pages or just several pages with specific names.

Failed to convert page when sub pages are double nested

Single nesting pages in the right panel is fine, however, when we have a double nesting I find we face conversion problems:

Root
> > Nested Double Space
> > Nested Double Space v2
> Nested 2.2

Example image where error is thrown:

image

Error message:

### Nested 2.2 [Page]
Failed to convert page: test-Section-1\Nested-2.2. Reason: Failed to create directory '\': The path is not of a legal form.
Convert-OneNotePage : Failed to convert page: test-Section-1\Nested-2.2. Reason: Failed to create directory '\': The path is not of a legal form.
At C:\{REDACTED PATH}\ConvertOneNote2MarkDown-v2.ps1:1247 char:254
+ ... onConfigs | Convert-OneNotePage -OneNoteConnection $OneNote -Config $ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNotePage

Onenote code formatting doesn't get converted to markdown code blocks

Current

State the current behavior in one sentence.

Onenote code formatting doesn't get converted to markdown code blocks

Expectation

State the feature in one sentence.
The code should be converted to markdown code blocks using ```

Ex -

import sqllite3

Discussion

Describe the feature.

Reopen #5 Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].

Hi Nixsee,
I'm not sure why this was closed, as the previous OP never said it was resolved.
I'm running into the exact same issue, tried it various ways, but currently, Office 2016-Desktp, and both VS Code and OneNote running as Admin.

Enter the (preferably empty!) folder path (without trailing backslash!) that will contain your resulting Notes structure. ex. 'c:\temp\notes'
Entry: D:\docs1



1: Create new .docx files - Default
2: Use existing .docx files (90% faster)
Entry:


1: Discard intermediate .docx files - Default
2: Keep .docx files
Entry: 2


1: Create folders for subpages (e.g. Page\Subpage.md)- Default
2: Add prefixes for subpages (e.g. Page_Subpage.md)
Entry:


1: Images stored in single 'media' folder at Notebook-level (Default)
2: Separate 'media' folder for each folder in the hierarchy
Entry:

Select conversion type

1: markdown (Pandoc) - Default
2: commonmark (CommonMark Markdown)
3: gfm (GitHub-Flavored Markdown)
4: markdown_mmd (MultiMarkdown)
5: markdown_phpextra (PHP Markdown Extra)
6: markdown_strict (original unextended Markdown)
Entry: :

1: Clear double spaces in bullets - Default
2: Keep double spaces
Entry:

1: Clear '' symbol escape character from files
2: Keep '' symbol escape
Entry:
InvalidOperation: D:!foam\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:361:31
Line |
361 | … erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].

Latest stable Powershell support

Current

Script doesn't work with PowerShell 7.3.5

Expectation

Script should work with PowerShell 7.3.5+ ( latest stable release at the time).

Discussion

It would be good to follow up-to-date version of PowerShell since it seems to be widely used.
Chocolatey downloads of latest stable release counts 3,453,262 assuming most people update regularly.
Windows updater updates PowerShell to latest version.

It would be better then install older version just to run single script.

Thank you for your time and efforts.

Unable to cast COM object

Bug

Getting error Unable to cast COM object.

Expectation

That it would finish/convert.

Discussion

Running in VS Code. Pandoc and Onetastic installed. OneNote is open. Got this error:

Convert-OneNote2MarkDown : Exception calling "GetHierarchy" with "3" argument(s): "Unable to cast COM object 
of type 'Microsoft.Office.Interop.OneNote.Application2Class' to interface type 
'Microsoft.Office.Interop.OneNote.IApplicationCOM'. This operation failed because the QueryInterface call on   
the COM component for the interface with IID '{452AC71A-B655-4967-A208-A4CC39DD7949}' failed due to the        
following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A
(TYPE_E_CANTLOADLIBRARY))."
At D:\Github Clones\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown       

Convert-OneNote2MarkDown : at Get-OneNoteHierarchy, D:\Github
Clones\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line 568
at Convert-OneNote2MarkDown, D:\Github Clones\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line     
1362
at <ScriptBlock>, D:\Github Clones\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1: line 1423
At D:\Github Clones\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown-v2.ps1:1423 char:5
+     Convert-OneNote2MarkDown @params
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-OneNote2MarkDown

Environment

Output of Configuration

Configuration:
Configuration:
dryRun: 1
notesdestpath: c:\onenote-conversion\
targetNotebook: 
usedocx: 2
keepdocx: 2
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 255
medialocation: 1
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 1
exportPdf: 1

Output of $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Exception: Exception calling "Publish" with "4" argument(s): "0x80042006"

Bug

Failure to export to word, PowerShell gives an error saying "Exception: Exception calling "Publish" with "4" argument(s): "0x80042006""

Expectation

During the conversion, OneNote notes should be exported to Word and then converted to Md.

Discussion

The conversion worked well at the beginning, then this error alert started to happen for each document. After I turned off the codes, I found that there are many word processes opened in the task manager (I bet there are over 30 processes... see the image below). It is normal? Could it be the reason why this error occurs?

task manager screenshot

Environment

I am using Office 365 and use a notebook folder in onedrive, inside of it is the internet shortcut pointing to the onenote online. I tried to run the code in a local folder with .one files, but it won't work.

Output of Configuration

Configuration:
dryRun: 0
notesdestpath: C:\Users\verac\OneDrive\Documents\Notebooks
targetNotebook:
usedocx: 2
keepdocx: 1
docxNamingConvention: 1
prefixFolders: 1
mdFileNameAndFolderNameMaxLength: 200
medialocation: 2
conversion: markdown-simple_tables-multiline_tables-grid_tables+pipe_tables
headerTimestampEnabled: 1
keepspaces: 1
keepescape: 1
newlineCharacter: 2
exportPdf: 1

Output of $PSVersionTable

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.13
PSEdition                      Core
GitCommitId                    7.0.13
OS                             Microsoft Windows 10.0.22622
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

MS Word only supports 9 levels of bullets

Bug

Hi guys, I'm back after a long time away from markdown! I finally tried your improvements and it is fantastic!

I've noticed one bug that is inherent to Word and pandoc... Word only supports 9 levels of bullets. If you export a OneNote page that has more than that, the resulting word doc actually does show all levels. However, the final markdown file cuts it at 9 levels and moves the remaining levels to level 1, 2, 3, etc... In fact, it completely destroys the nesting that follows it.

Expectation

The final markdown nested levels match the levels in OneNote

Discussion

The markdown contains some sort of divider symbol where it cuts off the 9 levels.

This:

image

ends up like this:
image

Perhaps we could somehow look for any <!-- --> sections and remove them and indent what follows? I really don't know

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.