Two Ways to Search Essbase Exports with PowerShell

Every now and again you may get a request to check for data in Essbase text exports.

We do them nightly so it’s very easy to prove what day someone may have added or deleted some data based on if it exists.

Here are two different ways to look for them.

Method 1: Using .NET

Clear-Host
$search = $null
$rootFolder = "C:\EssbaseRestores"
$searchFilter = "P2000000572"
$files = @()
$found = $false

Write-Output "===========STARTING SEARCH==================="
$search = Get-ChildItem -Path $rootFolder -Recurse |
    Where {$_.PSIsContainer -eq $false} | foreach {
        foreach ($line in [System.IO.File]::ReadLines($_.FullName)) {
            if ($line -match $searchFilter) {
                Write-Output $line
                $found=$true
            }
        }
        if($found) {$files += $_.FullName}
        $found = $false
    }
Write-Output "===========SEARCH RESULTS=================="
if ($search) {
    Write-Output "Search found results!"
    $files
} else {
    Write-Output "Search turned up nothing"
}
Write-Output "===========SEARCH COMPLETED=================="

Method 2: Using the get-content commandlet.

Clear-Host
$search = $null
$rootFolder = "C:\EssbaseRestores"
$searchFilter = "P2000000572"
$files = @()
$found = $false

Write-Output "===========STARTING SEARCH==================="
$search = Get-ChildItem -Path $rootFolder -Recurse |
    Where {$_.PSIsContainer -eq $false} |
    Get-Content -ReadCount 512 |
    Where {$_ -match $searchFilter}
Write-Output "===========SEARCH COMPLETED=================="
if ($search) {
    Write-Output "Search found results!"
    $search | Select PSPath -Unique
} else {
    Write-Output "Search turned up nothing"
}

The second method is more concise but your mileage may vary. I tend to prefer the .Net approach myself.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s