Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

Count pages in onenote using Powershell

$
0
0

 

[필요 사항]

쉐어포인트 서버에 있는 원노트에 페이지 수가 몇개인지 알아야 할 경우가 있습니다

 

[해결 방법]

쉐어포인트 서버에 업로드 된 원노트의 내부 구조에 접근할 수 있는 Server side 방법은 존재하지 않습니다.

물론 서버에서 one 파일을 로컬 드라이브로 내려 받아 코드로 접근하여 어찌어찌 하는 방법이 있을 수 있겠지만… 그런 방식은 논외로 하겠습니다.

 

가장 쉽고 빠르게 구현가능한 방법은 원노트 클라이언트가 설치된 PC 에서 원노트 Application interface 를 활용하는 방법이 유일합니다.

https://msdn.microsoft.com/en-us/library/office/jj680120.aspx

위 링크에 제공하고 있는 API를 활용해 C# 어플리케이션을 개발하는 것이 가능합니다.

 

위 인터페이스를 활용하여 간단한 파워쉘 스크립트를 작성하였으니 참고 부탁 드립니다.

아래의 파워쉘 스크립트를 통해 현재 PC 에 사용중인 원노트의 페이지 수를 출력할 수 있습니다.

페이지 수를 알고자 하는 원노트 파일을 PC 에 동기화 하신 후 실행하시면 됩니다.

 

 

[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null
$onenoteApp = New-Object -ComObject OneNote.Application

# init empty Variable for as buffer the [Ref] output action
[String]$notebookXml = ''

# Get OneNote Pages hierarchy
$onenoteApp.GetHierarchy($null, [Microsoft.Office.Interop.OneNote.HierarchyScope]::hsPages, [Ref]$notebookXml)

# Create the System.Xml.Linq.XDocument from an XML Text
# alternatively you can use the [System.Xml.Linq.XDocument]::Load('C:tempmyXML.xml') Methode to load from a XML File
$doc = [System.Xml.Linq.XDocument]::Parse($notebookXml)

# Get OneNote XML namespace
$ns = $doc.Root.Name.Namespace

$pagecount_notebook = 0
$pagecount_section = 0

# enumerate all Notebook Nodes from XML XDocument
$doc.Descendants($ns + "Notebook") | ForEach-Object {

    # output name of current OneNote Notebook
    "Notebook name: $($_.Attribute("name").Value)"

        # enumerate all Section Nodes from Notebook Node
        $_.Descendants($ns + "Section") | ForEach-Object {

           # output name of current OneNote Section
           #"    Section: $($_.Attribute("name").Value)"

           # enumerate all Page Nodes from Section Node
           $_.Descendants($ns + "Page")  | ForEach-Object {

                # output name of current OneNote Page
                #"        Page: $($_.Attribute("name").Value)"
                $pagecount_notebook = $pagecount_notebook + 1
                $pagecount_section = $pagecount_section + 1
           }
           "    ## Section: $($_.Attribute("name").Value) ==> " + $pagecount_section + " pages"
            $pagecount_section = 0
        }
    "##Notebook name: $($_.Attribute("name").Value) ==> " + $pagecount_notebook + " pages"
    $pagecount_notebook = 0
    "---------------------------------------------------"
}

위 스크립트의 수행결과는 아래와 같이 출력됩니다

Notebook name: Provisioning – Tenant – Site

    ## Section: Deep Dives ==> 5 pages

    ## Section: Troubleshooting Guide ==> 26 pages

##Notebook name: Provisioning – Tenant – Site ==> 31 pages

—————————————————

Notebook name: Yammerkorea101

    ## Section: Yammer Support 101 ==> 12 pages

    ## Section: New Section 1 ==> 1 pages

##Notebook name: Yammerkorea101 ==> 13 pages

—————————————————

 

만약 SharePoint Online 을 사용하신다면, 아래 링크에서 제공하는 Office 365용 onenote api를 사용하여 원하시는 기능을 구현하는 것이 가능합니다.

https://msdn.microsoft.com/ko-kr/office/office365/howto/onenote-tutorial

 

[주의 사항]

본 블로그에 게시된 정보의 내용 (첨부 문서, 링크 등)은 작성일 현재 기준이며 예고없이 변경 될 수 있습니다.

또한, 참고용으로만 제공됨으로 Microsoft에 책임이 없음을 알려 드립니다. 반드시 적용 전 충분한 테스트를 진행하시기 바랍니다.


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>