---
updatedAt: 2026-06-05T07:47:53.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-able-cove/llms.txt
---

# Cove - ClientTool - Export Session File Lists

```powershell PowerShell
<#
.SYNOPSIS
    Clienttool-Export-SessionFiles.ps1 v1.1 | Head Backup Nerd - Eric Harless
    Export Cove Backup session file lists to CSV via ClientTool.exe.

.DESCRIPTION
    Lists backup sessions for a given datasource via ClientTool.exe, presents them
    in Out-GridView for multi-selection, then exports the filtered file list for
    each selected session to a CSV in the output folder.

    --- Behavior ---
    · List sessions for -DataSource via ClientTool.exe
    · Present in Out-GridView for multi-select (oldest → newest)
    · Fetch file nodes per session; tag State: Changed / Unchanged / Removed
    · Filter by -PathFilter wildcard; export to CSV
    · Display rolling elapsed time + ETC after each session
    · Append structured run block to Clienttool-Export-SessionFiles.log

    --- Output ---
    CSV:  {device}_{DataSource}_session_{starttime}.csv  (OutputFolder)
    Log:  {OutputFolder}\Clienttool-Export-SessionFiles.log  (append)

    --- Legal ---
    Sample scripts are not supported under any N-able support program or service.
    The sample scripts are provided AS IS without warranty of any kind.
    N-able expressly disclaims all implied warranties including, warranties
    of merchantability or of fitness for a particular purpose.
    In no event shall N-able or any other party be liable for damages arising
    out of the use of or inability to use the sample scripts.
    May contain non-public API calls subject to change without notice.

.PARAMETER PathFilter
    Wildcard filter applied to file paths (case-insensitive, PowerShell -like syntax).
    Omit or pass '' to export all files regardless of path.
    Examples:
      'C:\Users*'       — prefix  (everything under C:\Users)
      '*\Users\*'       — contains
      '*.pdf'           — ends with
      '*\logs\*.txt'    — combined

.PARAMETER ClientToolPath
    Full path to ClientTool.exe.
    Default: 'C:\Program Files\Backup Manager\ClientTool.exe'

.PARAMETER IncludeChanged
    Include files that were backed up (sent bytes > 0). Default: $true

.PARAMETER IncludeUnchanged
    Include files that were scanned but not re-uploaded (sent bytes = 0). Default: $true

.PARAMETER IncludeRemoved
    Include files that were deleted/removed in this session. Default: $false
    Requires a second ClientTool call per session.

.PARAMETER DataSource
    ClientTool datasource to enumerate sessions for.
    Valid values: Exchange, FileSystem, MySql, NetworkShares, Oracle,
                  SystemState, VMware, VssHyperV, VssMsSql, VssSharePoint
    Default: FileSystem

.PARAMETER OutputFolder
    Destination folder for CSV files.
    Default: <script dir>\output

.EXAMPLE
    .\Clienttool-Export-SessionFiles.V01.1.ps1 -PathFilter 'C:\Users*'
    Export all Changed + Unchanged files under C:\Users from FileSystem sessions (prefix match).

.EXAMPLE
    .\Clienttool-Export-SessionFiles.V01.1.ps1 -PathFilter '*\Users\*' -IncludeUnchanged $false -IncludeRemoved $true
    Export only Changed and Removed files whose path contains \Users\ (contains match).

.EXAMPLE
    .\Clienttool-Export-SessionFiles.V01.1.ps1 -DataSource VssMsSql
    Export all files from VssMsSql sessions with no path filter.

.EXAMPLE
    .\Clienttool-Export-SessionFiles.V01.1.ps1 -PathFilter '*.pdf' -IncludeChanged $true -IncludeUnchanged $false -OutputFolder 'C:\Temp\exports'
    Export only Changed PDF files from FileSystem sessions; write CSVs to C:\Temp\exports.

.NOTES
    Author  : Eric Harless, Head Backup Nerd - N-able
    Twitter : @Backup_Nerd  |  Email: eric.harless@n-able.com
    Reddit  : https://www.reddit.com/r/Nable/
    Version : 1.1  |  2026-06-05
    Platform: N-able Cove Data Protection Backup Manager (local agent only)
#>
#Requires -Version 5.1
[CmdletBinding()]
param(
    [string]$PathFilter = '',

    [string]$ClientToolPath = 'C:\Program Files\Backup Manager\ClientTool.exe',

    [bool]$IncludeChanged   = $true,
    [bool]$IncludeUnchanged = $true,
    [bool]$IncludeRemoved   = $false,

    [ValidateSet('Exchange','FileSystem','MySql','NetworkShares','Oracle',
                 'SystemState','VMware','VssHyperV','VssMsSql','VssSharePoint')]
    [string]$DataSource = 'FileSystem',

    [string]$OutputFolder = (Join-Path $PSScriptRoot 'output')
)

if (-not $IncludeChanged -and -not $IncludeUnchanged -and -not $IncludeRemoved) {
    Write-Error 'At least one of -IncludeChanged, -IncludeUnchanged, or -IncludeRemoved must be $true.'
    exit 1
}

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

# ---------------------------------------------------------------------------
# Logging helper — writes to console and appends to log file
# ---------------------------------------------------------------------------
$script:LogFile = $null   # set after OutputFolder is confirmed to exist

function Write-Log {
    param(
        [string]$Message,
        [string]$Color = 'Gray',
        [switch]$NoEcho
    )
    if (-not $NoEcho) { Write-Host $Message -ForegroundColor $Color }
    if ($script:LogFile) {
        Add-Content -LiteralPath $script:LogFile -Value $Message -Encoding UTF8
    }
}

# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
function Resolve-ColumnName {
    param([object]$Row, [string[]]$Candidates)
    foreach ($c in $Candidates) {
        if ($Row.PSObject.Properties.Name -contains $c) { return $c }
    }
    return $null
}

# ---------------------------------------------------------------------------
# 1. Validate ClientTool
# ---------------------------------------------------------------------------
if (-not (Test-Path -LiteralPath $ClientToolPath)) {
    Write-Error "ClientTool.exe not found at: $ClientToolPath"
    exit 1
}

# ---------------------------------------------------------------------------
# 2. Get the Cove device / account name for the filename prefix
# ---------------------------------------------------------------------------
$deviceName = $env:COMPUTERNAME   # safe fallback

try {
    $statusLines = & $ClientToolPath -machine-readable control.status.get -delimiter "`t" 2>$null
    if ($statusLines) {
        $statusObj  = $statusLines | ConvertFrom-Csv -Delimiter "`t" | Select-Object -First 1
        $nameCol    = Resolve-ColumnName $statusObj 'AccountName','Account','Name','MachineName'
        if ($nameCol -and $statusObj.$nameCol) {
            $deviceName = $statusObj.$nameCol
        }
    }
} catch {
    Write-Warning "Could not read device name from ClientTool — using computer name: $deviceName"
}

$safeDevice = $deviceName -replace '[\\/:*?"<>| ]', '_'
$originalTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "Clienttool-Export-SessionFiles  |  $deviceName  |  $DataSource"
Write-Host "Device : $deviceName" -ForegroundColor DarkCyan

# ---------------------------------------------------------------------------
# 3. List FileSystem sessions
# ---------------------------------------------------------------------------
Write-Host "Fetching $DataSource sessions..." -ForegroundColor Cyan

$sessionRaw = & $ClientToolPath -machine-readable control.session.list `
    -datasource $DataSource -delimiter "`t" 2>&1

if ($LASTEXITCODE -ne 0) {
    Write-Error "control.session.list failed (exit $LASTEXITCODE):`n$sessionRaw"
    exit 1
}

$sessions = $sessionRaw | ConvertFrom-Csv -Delimiter "`t"

if (-not $sessions) {
    Write-Warning "No FileSystem sessions found on this device."
    exit 0
}

Write-Host "  Found $(@($sessions).Count) sessions." -ForegroundColor DarkCyan

# Discover column names — ClientTool uses short uppercase headers (START, END, STATE, etc.)
# START is the session timestamp used as both the display key and the -time selector.
$colStart = Resolve-ColumnName ($sessions | Select-Object -First 1) 'START','StartTime','Start'
if (-not $colStart) { $colStart = 'START' }

# ---------------------------------------------------------------------------
# 4. Present all sessions in Out-GridView for multi-select
# ---------------------------------------------------------------------------
$selected = $sessions | Out-GridView -PassThru `
    -Title "Select sessions to export  [device: $deviceName  |  datasource: $DataSource  |  filter: $PathFilter]"

if (-not $selected) {
    Write-Host "No sessions selected — exiting." -ForegroundColor Yellow
    exit 0
}

Write-Host "Selected $(@($selected).Count) session(s)." -ForegroundColor Cyan

# ---------------------------------------------------------------------------
# 5. Ensure output folder exists + open log file
# ---------------------------------------------------------------------------
if (-not (Test-Path -LiteralPath $OutputFolder)) {
    New-Item -ItemType Directory -Path $OutputFolder -Force | Out-Null
    Write-Host "Created output folder: $OutputFolder" -ForegroundColor DarkCyan
}

$script:LogFile = Join-Path $OutputFolder 'Clienttool-Export-SessionFiles.log'
$runStamp       = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$divider        = '=' * 80
$thinDivider    = '-' * 80

# Write run header to log
Write-Log $divider -NoEcho
Write-Log "Clienttool-Export-SessionFiles  $runStamp" -NoEcho
Write-Log $divider -NoEcho
Write-Log "Device           : $deviceName" -NoEcho
Write-Log "PathFilter       : $PathFilter" -NoEcho
Write-Log "DataSource       : $DataSource" -NoEcho
Write-Log "IncludeChanged   : $IncludeChanged" -NoEcho
Write-Log "IncludeUnchanged : $IncludeUnchanged" -NoEcho
Write-Log "IncludeRemoved   : $IncludeRemoved" -NoEcho
Write-Log "OutputFolder     : $OutputFolder" -NoEcho
Write-Log $thinDivider -NoEcho

# Normalise path filter once — swap forward slashes so -like comparisons are consistent
$normFilter = $PathFilter -replace '/', '\'

# ---------------------------------------------------------------------------
# 6. Sort selected sessions oldest → newest, then process
# ---------------------------------------------------------------------------
$selected = @($selected | Sort-Object { [datetime]$_.$colStart })
Write-Log "Sessions selected : $($selected.Count)  (processed oldest → newest)" -NoEcho
Write-Log "" -NoEcho

$exportCount  = 0
$skipCount    = 0
$errorCount   = 0
$sessionIdx   = 0
$sessionTotal = $selected.Count
$loopStart    = [datetime]::UtcNow

# Helper: write rolling elapsed + ETC line (called after every session outcome)
$writeETC = {
    $elapsed    = [datetime]::UtcNow - $loopStart
    $avgSecs    = $elapsed.TotalSeconds / $sessionIdx
    $remaining  = $sessionTotal - $sessionIdx
    $etcSecs    = $avgSecs * $remaining
    $elapsedFmt = '{0:mm\:ss}' -f $elapsed
    $etcFmt     = if ($remaining -gt 0) { '{0:mm\:ss}' -f ([timespan]::FromSeconds($etcSecs)) } else { '00:00' }
    Write-Log "        Elapsed: $elapsedFmt  |  ETC: $etcFmt  ($remaining remaining)" -Color DarkCyan
    $Host.UI.RawUI.WindowTitle = "[$sessionIdx/$sessionTotal] ETC $etcFmt  |  $deviceName  |  $DataSource"
}

foreach ($session in $selected) {
    $sessionIdx++
    $startTime  = $session.$colStart
    $logPrefix  = "  [$sessionIdx/$sessionTotal] $startTime"
    $Host.UI.RawUI.WindowTitle = "[$sessionIdx/$sessionTotal] $startTime  |  $deviceName  |  $DataSource"

    Write-Log "$logPrefix — fetching file list..." -Color Cyan

    $nodeRaw = & $ClientToolPath -machine-readable control.session.node.list `
        -datasource $DataSource -time $startTime -delimiter "`t" 2>&1

    if ($LASTEXITCODE -ne 0) {
        $errorCount++
        Write-Log "$logPrefix  ERROR — control.session.node.list exit $LASTEXITCODE" -Color Red
        Write-Log "        stderr: $($nodeRaw -join ' ')" -Color Red
        & $writeETC
        continue
    }

    if (-not $nodeRaw) {
        $skipCount++
        Write-Log "$logPrefix  SKIPPED — no output returned" -Color Yellow
        & $writeETC
        continue
    }

    $nodes = $nodeRaw | ConvertFrom-Csv -Delimiter "`t"

    if (-not $nodes) {
        $skipCount++
        Write-Log "$logPrefix  SKIPPED — no file records parsed" -Color Yellow
        & $writeETC
        continue
    }

    # Detect the path column — ClientTool node list uses 'PATH'; older versions may vary
    $pathCol = Resolve-ColumnName ($nodes | Select-Object -First 1) 'PATH','Path','FullPath','NodePath','FileName','Name'

    if (-not $pathCol) {
        $errorCount++
        Write-Log "$logPrefix  ERROR — could not identify path column. Available: $(($nodes | Select-Object -First 1).PSObject.Properties.Name -join ', ')" -Color Red
        & $writeETC
        continue
    }

    # Tag each present-in-session node with a State:
    #   Changed   — SENTS > 0  (file was backed up / data transferred)
    #   Unchanged — SENTS == 0 (scanned, already up to date)
    foreach ($n in $nodes) {
        $sentVal  = ($n.SENTS -replace '[^0-9]', '') -as [long]
        $stateVal = if ($sentVal -gt 0) { 'Changed' } else { 'Unchanged' }
        $n | Add-Member -NotePropertyName 'State' -NotePropertyValue $stateVal -Force
    }

    # Optionally fetch removed files (requires a second ClientTool call)
    $removedNodes = @()
    if ($IncludeRemoved) {
        $removedRaw = & $ClientToolPath -machine-readable control.session.node.list `
            -datasource $DataSource -time $startTime -removed -delimiter "`t" 2>&1
        if ($LASTEXITCODE -eq 0 -and $removedRaw) {
            $removedNodes = @($removedRaw | ConvertFrom-Csv -Delimiter "`t")
            foreach ($n in $removedNodes) {
                $n | Add-Member -NotePropertyName 'State' -NotePropertyValue 'Removed' -Force
            }
        }
    }

    # Apply IncludeChanged / IncludeUnchanged filters, then append removed
    $combined = @(
        if ($IncludeChanged)   { $nodes | Where-Object { $_.State -eq 'Changed'   } }
        if ($IncludeUnchanged) { $nodes | Where-Object { $_.State -eq 'Unchanged' } }
        if ($IncludeRemoved)   { $removedNodes }
    )

    # Filter by path pattern (case-insensitive -like wildcard); skip when filter is empty
    $filtered = if ($normFilter -eq '') {
        $combined
    } else {
        $combined | Where-Object {
            $p = ($_.${pathCol} -replace '/', '\')
            $p -like $normFilter
        }
    }

    if (-not $filtered) {
        $skipCount++
        $filterMsg = if ($normFilter -eq '') { '' } else { " matching filter '$PathFilter' with" }
        Write-Log "$logPrefix  SKIPPED — no files${filterMsg} current state filters" -Color Yellow
        & $writeETC
        continue
    }

    # Build a filesystem-safe timestamp from the session start time
    $safeTime = $startTime -replace '[:\\/ ]', '-' -replace '-{2,}', '-'
    $csvName  = "${safeDevice}_${DataSource}_session_${safeTime}.csv"
    $csvPath  = Join-Path $OutputFolder $csvName

    # Reorder so State is the first column in the CSV
    $colOrder = @('State') + ($filtered | Select-Object -First 1).PSObject.Properties.Name.Where({ $_ -ne 'State' })
    $filtered | Select-Object $colOrder | Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8

    $exportCount++
    $stateSummary = ($filtered | Group-Object State | ForEach-Object { "$($_.Name)=$($_.Count)" }) -join '  '
    Write-Log "$logPrefix  → $csvName" -Color Green
    Write-Log "        $stateSummary  Total=$($filtered.Count)" -Color Green
    & $writeETC
}

# ---------------------------------------------------------------------------
# 7. Log footer + summary
# ---------------------------------------------------------------------------
Write-Log "" -NoEcho
Write-Log $thinDivider -NoEcho
$resultLine = "Result   : $exportCount exported  |  $skipCount skipped  |  $errorCount errors"
Write-Log $resultLine -Color Cyan
Write-Log "Log file : $script:LogFile" -NoEcho
Write-Log $divider -NoEcho
Write-Log "" -NoEcho

Write-Host "Log : $script:LogFile" -ForegroundColor DarkCyan
$Host.UI.RawUI.WindowTitle = $originalTitle

```

```json Response Example
Device : NABLE-CS66194
Fetching FileSystem sessions...
  Found 340 sessions.
Selected 8 session(s).
  [1/8] 2026-06-01 12:00:00 — fetching file list...
  [1/8] 2026-06-01 12:00:00  → NABLE-CS66194_FileSystem_session_2026-06-01-12-00-00.csv
        Changed=158  Unchanged=18  Total=176
  [2/8] 2026-06-01 18:00:00 — fetching file list...
  [2/8] 2026-06-01 18:00:00  → NABLE-CS66194_FileSystem_session_2026-06-01-18-00-00.csv
```

# Summary

<!-- powershell@ -->

Uses the Cove ClientTool.exe command-line utility to  list sessions for a given datasource in an interactive  Out-GridView picker, then exports  the file node list for each selected session CSV.