llf
llf

Reputation: 630

Automatically export a OneNote section to PDF

I have a .one OneNote section file that I would like to automatically export to PDF at regular intervals. In Powershell 7, I discovered this command:

Start-Process "C:\path\to\ONENOTE.EXE" -ArgumentList "/print `"C:\path\to\my_section.one`""

This opens OneNote and the save location dialog for the PDF, but I can't figure out how to provide input to this dialog at the command line. I'm not sure if there's an appropriate module - I looked at https://www.powershellgallery.com/ and couldn't find one. Any ideas on how to extend the above command, or another solution entirely?

Upvotes: 0

Views: 1013

Answers (1)

postanote
postanote

Reputation: 16116

As per my comment. Your use case could be as simple as this:

$CurrentDefaultPrinter = (
Get-CimInstance -Class Win32_Printer | 
Where-Object {$PSItem.Default -eq $true}
).Name

$CurrentDefaultPrinter 

Get-Printer | 
Where-Object {$PSItem.Name -Match 'pdf'} | 
Set-Printer -Name $PSItem.Name
Start-Process 'C:\path\to\ONENOTE.EXE' -FilePath 'C:\path\to\my_section.one' -Verb Print

Set-Printer -Name $CUrrentDefaultPrinter

Upvotes: 0

Related Questions