internal/Get-OlaHRestoreFile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Get-OlaHRestoreFile
{
<#
.SYNOPSIS
Internal Function to get SQL Server backfiles from a specified folder that's formatted according to Ola Hallengreen's scripts.
 
.DESCRIPTION
Takes path, checks for validity. Scans for usual backup file
#>

    [CmdletBinding()]
    Param (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string]$Path
    )
    $FunctionName = (Get-PSCallstack)[0].Command
    
    Write-Verbose "$FunctionName - Starting"
    Write-Verbose "$FunctionName - Checking Path"
    
    if ((Test-Path $Path) -ne $true)
    {
        Write-Warning "$FunctionName - $Path is not valid"
        return
    }
    
    #There should be at least FULL folder, DIFF and LOG are nice as well
    Write-Verbose "$FunctionName - Checking we have a FULL folder"
    
    if (Test-Path -Path $Path\FULL)
    {
        Write-Verbose "$FunctionName - We have a FULL folder, scanning"
        $Results = Get-ChildItem -Path $Path\FULL -Filter *.bak
        $results = @($results)
    }
    else
    {
        if ($MaintenanceSolutionBackup)
        {
            Write-Warning "$FunctionName - Don't have a FULL folder"
        }
        else
        {
            Write-Warning "$FunctionName - No valid backup found - even tried MaintenanceSolution structure"
        }
        
        return
    }
    if (Test-Path -Path $Path\Log)
    {
        Write-Verbose "$FunctionName - We have a LOG folder, scanning"
        $Results += Get-ChildItem -Path $Path\LOG -filter *.trn
    }
    if (Test-Path -Path $Path\Diff)
    {
        Write-Verbose "$FunctionName - We have a DIFF folder, scanning"
        $Results += Get-ChildItem -Path $Path\DIFF -filter *.bak
    }
    
    return $Results
}