# CyberArkからのインポート

<figure><img src="https://2985347814-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Y1mjnoaNcCi93oXSTE3%2Fuploads%2Fxa69iE1BSTtOwFmZfzUP%2FImport%20from%20CyberArk.avif?alt=media&#x26;token=7303d631-4e00-426d-8eac-2b4d8c12c4f8" alt=""><figcaption></figcaption></figure>

Cyber​​Arkには、Cyber​​Ark Vaultと直接通信するコマンドラインインターフェイスPACLIが含まれています。これは、Vault内の「Safe」に保存されている「ファイル」に対して操作を行います。PACLIを使用すると、CyberArkのクライアント (例: PrivateArkやPassword Vault Web Access (PVWA)) がSafe内のファイルとして保存しているCyberArkアカウントデータをエクスポートすることができます。

以下の手順では、PACLIを使用してパターンに一致するすべてのファイルをエクスポートする PowerShellスクリプトを使用します。デフォルトのパターン「\*」を使用して、Safeからすべてのファイルをエクスポートします。それぞれのユーザー名、アドレス、パスワードを抽出しますが、必要に応じて他のフィールドを抽出するように構成することもできます。スクリプトはエクスポートされたファイルをオブジェクトにするので、ConvertTo-CSVを使用してそれらをカンマ区切り値 (CSV) 形式に変換し、Keeperにインポートします。

## 要件 <a href="#prerequisites" id="prerequisites"></a>

以下のスクリプトを使用するには、3つの外部コンポーネントが必要となります。

1. Cyber​​Ark PACLI
2. Vault.ini構成ファイル
3. User.ini認証情報ファイル

## Cyber​​Ark PACLI <a href="#cyberark-pacli" id="cyberark-pacli"></a>

PACLI は、Cyber​​Arkマーケットプレースウェブサイトからダウンロードできます。`PACLI.exe`バイナリといくつかのサポートファイルを含むzipファイルとなります。スクリプトでは、バイナリを含むディレクトリのパスが必要です。

## vault.ini <a href="#vault.ini" id="vault.ini"></a>

vault.iniファイルには、以下のようなPACLIがボルトを見つけてログオンするために必要なパラメータが含まれています。

```
VAULT=CAMainVault
ADDRESS=10.11.12.13
PREAUTHSECUREDSESSION=YES
TRUSTSSC=YES
```

VAULTは通常、「CAMainVault」のままにしておきます。

ADDRESSは、Cyber​​Ark Vaultサーバーのホスト名または IP アドレスです。

PREAUTHSECUREDSESSIONおよびTRUSTSSC設定は、ログオンユーザーが LDAP (Active Directory) またはRADIUS経由で認証される場合に必要となります。それ以外の場合は省略できます。

## user.ini <a href="#user.ini" id="user.ini"></a>

user.iniファイルはINI形式です。ただし、Cyber​​Arkに含まれる`CreateCredFile.exe`ツールとそのコンポーネントの一部を使用して生成されます。たとえば、CORP Active DirectoryドメインのMyuserのuser.iniを生成するには、以下を実行します。

```
CreateCredFile.exe User.ini Password /Username Myuser /Password "MyPassw0rd!" /ExternalAuth /OSUsername CORP\Myusername
```

PACLI zipの最新バージョンにはツールが含まれています。`/?`パラメータを指定して実行すると、他の認証状況で役立つ他のオプションが表示されます。

### エクスポート <a href="#export" id="export"></a>

以下を.ps1で終わるファイルに貼り付けます(例: Export-Cyber​​ArkSafeFiles.ps1)。

```python
<#
.SYNOPSIS
Exports 'files', i.e., CyberArk Account passwords from a CyberArk Safe using PACLI.

.DESCRIPTION
Uses CyberArk's PACLI command to export files from a CyberArk Safe.
It retrieves files, their categories, and contents and exports an object for each.
It uses filepattern=* to get all files in the safe by default.
The default categories are 'Address' and 'UserName'.
#>
param (
    # The name of the 'Vault' in CyberArk, e.g., 'CAMainVault'
    [Parameter(Mandatory = $true)][string]$VaultName,
    # The name of the 'Safe' in CyberArk
    [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SafeName,
    # The CyberArk log on user (must match credentials in the User.ini)
    [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Username,
    # The path to the PACLI directory containing PACLI.exe
    [Parameter(Mandatory = $true)]
    [ValidateScript({ Test-Path -PathType Leaf (Join-Path $_ 'PACLI.exe') })]
    [string]$PACLIPath,
    # Arguments `findfiles` uses to generate the list of files to export
    [string[]]$FindFilesArguments = 'filepattern=*',
    # The categories to export from the files
    [Parameter()][string[]]$Categories = @('Address', 'UserName'),
    # A CyberArk Vault.ini file
    [Parameter()][ValidateScript({ Test-Path $_ -PathType Leaf })]
    [string]$VaultIniPath = 'Vault.ini',
    # A CyberArk User.ini (or .cred) file as generated by CreateCredFile.exe
    [Parameter()][ValidateScript({ Test-Path $_ -PathType Leaf })]
    [string]$UserIniPath = 'User.ini',
    # The folder in the safe to export files from--most use 'Root'
    [string]$FolderName = 'Root',
    # The session ID to use for the underlying PACLI commands
    [Parameter()][ValidateNotNullOrEmpty()][string]$SessionId,
    # ErrorAction for retrievefile errors
    [Parameter()][ValidateSet('Stop', 'Continue', 'SilentlyContinue')]
    [string]$PACLIErrorAction = 'Continue'
)

$PACLI = Join-Path $PACLIPath 'PACLI.exe' -Resolve

function Invoke-PACLI {
    param (
        [Parameter(Mandatory = $True)][string]$Command,
        [Parameter(ValueFromRemainingArguments)][string[]]$Arguments
    )
    $Executable = ".\{0}" -f (Split-Path -Leaf $PACLI)
    $CommandLine = "$Executable $Command $($Arguments -join ' ')"
    try {
        Push-Location $(Split-Path -Parent $PACLI) -StackName 'PACLI'
        $Output = (& $Executable $Command $Arguments 2>$null)
        if ($LastExitCode -eq 0) {
            $Output
        }
        else {
            switch ($PACLIErrorAction) {
                'Continue' {
                    Write-Error "'$CommandLine' exited with code $LastExitCode"
                }
                'Stop' { throw "'$CommandLine' exited with code $LastExitCode" }
            }
        }
    }
    finally {
        Pop-Location -StackName 'PACLI'
    }
}

Invoke-PACLI init

$PACLIDefaults = "vault=$VaultName", "user=$Username", "safe=$SafeName", 
"folder=$FolderName"
if ($SessionId) {
    $PACLIDefaults += "sessionId=$SessionId"
}
Invoke-PACLI default @PACLIDefaults
Invoke-PACLI definefromfile vault=$VaultName parmfile=(Resolve-Path $VaultIniPath) |
Out-Null
Invoke-PACLI logon logonfile=(Resolve-Path $UserIniPath) | Out-Null
Invoke-PACLI opensafe | Out-Null

try {
    # Create a temporary file to store the file contents during processing
    $tempFile = [IO.Path]::GetTempFileName()
    # Split the tempFile path into the folder and the filename for 'retrievefile'
    $localFolder = Split-Path $tempFile
    $localFile = Split-Path -Leaf $tempFile

    # Get the list of files in the safe
    Invoke-PACLI findfiles $FindFilesArguments 'output(name)' |
    Where-Object { $_.Trim() -ne '' } |
    ForEach-Object {
        $file = @{ Name = $_ }
        # Retrieve the file and store the contents (the password) in the file object
        Invoke-PACLI retrievefile file=$_ localfolder=$localFolder localfile=$localFile
        if ($LastExitCode -ne 0) { return }
        $file.Password = (Get-Content $tempFile).TrimEnd([Char]0) # Can be null-padded
        # Get the list of categories for the file as a quoted CSV string
        Invoke-PACLI listfilecategories file=$_ 'output(all,enclose)' |
        ForEach-Object {
            # Get the category name and value and strip the quotes
            $category = ($_ -split ',' | ForEach-Object { $_.Trim('"') })[0..1]
            # Add the category to the file object if it is on the list
            if ($category[0] -in $Categories) {
                $file[$category[0]] = $category[1]
            }
        }
        [PSCustomObject]$file
    }
}
finally {
    Remove-Item -Path $tempFile -Force
}

Invoke-PACLI closesafe vault=$VaultName user=$Username safe=$SafeName | Out-Null
Invoke-PACLI logoff vault=$VaultName user=$Username | Out-Null
Invoke-PACLI term | Out-Null
```

PACLI.zip を、スクリプトを含むディレクトリと同じディレクトリまたはサブディレクトリに展開します。

PowerShellを開き、スクリプトが含まれているディレクトリに移動します。

スクリプトを実行し、出力を[Export-CSV](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv)にパイプします。

```
.\Export-CyberArkSafeFiles.ps1 CAMainVault MySafe Myuser .\PACLI-Rls-v11.5.3 |
Export-CSV Records.csv -Delimiter "`t" -Encoding utf8 -NoHeader -UseQuotes Never
```

Keeper がデータを適切にインポートするには、カンマの代わりにタブ文字を使用すること、UTF-8 エンコードを使用すること、ヘッダーを除外すること、データを引用符で囲まないことが重要となります。

## 変換 <a href="#transformation" id="transformation"></a>

PowerShellでは、データをCSVとしてフォーマットするだけでなく、変換するのにも役立ちます。このより高度な例では、ユーザー名フィールドとアドレスフィールドを組み合わせて「ログイン」フィールドを作成し、それを「タイトル」フィールドとしても使用します。

```python
.\Export-CyberArkSafeFiles.ps1 CAMainVault MySafe Myuser .\PACLI-Rls-v11.5.3 |
Select-Object @{l='Folder';e={$_.Name -replace "-$($_.Address)-$($_.Username)", '' }},
 @{l='Login';e={'{0}@{1}' -f $_.Username, $_.Address}}, Password |
Select-Object Folder, @{l='Title';e={$_.Login}}, Login, Password |
Export-Csv Records.csv -Delimiter "`t" -Encoding utf8 -NoHeader -UseQuotes Never
```

## インポート <a href="#import" id="import"></a>

インポート手順について詳しくは[こちらのページ](/user-guides/jp/import-records-1/import-a-.csv-file.md)をご参照ください。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/user-guides/jp/import-records-1/import-from-cyberark.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
