1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PowerShell】Notes 文書を CSV ファイルにエクスポートする

Last updated at Posted at 2022-03-29

概要

VBA のサンプルはたくさんあるので、PowerShell(Ver5.1) で書いてみました。

前提

LotusScript は 32bit版 PowerShell でしか動作しません。

ソース

Export-Csv.ps1
using namespace System.IO;

# [32bit版 PowerShell](C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe) でしか使えません。
Param (
    # Notes DB ファイルパス
    [Parameter(Mandatory, ValueFromPipeline, Position=0)]
    [FileInfo] $Path
) Begin {
    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop

    # Notes を設定するセッション接続
    $Notes = New-Object -ComObject Lotus.NotesSession
    $Notes.Initialize('')
} Process {
    $db = $Notes.GetDatabase('', $Path, $false) 

    $Title = $db.Title
    $Documents = $db.AllDocuments

    $doc = $Documents.GetFirstDocument()
    $rows = if ($doc) {
        do {
            $row = @{}
            $doc.Items | % {
                if (![string]::IsNullOrEmpty($_.Name)) {
                    $row.Add($_.Name, $_.Text)
                }
            }

            [PSCustomObject]$row

            $doc = $Documents.GetNextDocument($doc)
        } while ($doc)
    }

    if ($rows) {
        pushd $Path.DirectoryName

        $rows | Export-Csv -NoTypeInformation "$Title.csv" -Encoding UTF8

        popd
    }
} End {
    $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
}

使い方

Notes 文書ファイル(.nsf) をパイプラインで渡せます。

dir C:\NotesDb -File -Recurse -Include *.nsf | .\Export-Csv.ps1

参考サイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?