functions/Get-DBOPackage.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Function Get-DBOPackage {
    <#
    .SYNOPSIS
    Shows information about the existin DBOps package
     
    .DESCRIPTION
    Reads DBOps package header and configuration files and returns an object with corresponding properties.
     
    .PARAMETER Path
    Path to the DBOps package
 
    Aliases: Name, FileName, Package
     
    .PARAMETER InputObject
    Pipeline implementation of Path. Can also accept a DBOpsPackage object.
 
    .PARAMETER Unpacked
    Mostly intended for internal use. Gets package information from extracted package.
 
    .PARAMETER Confirm
        Prompts to confirm certain actions
 
    .PARAMETER WhatIf
        Shows what would happen if the command would execute, but does not actually perform the command
 
    .EXAMPLE
    # Returns information about the package myPackage.zip, only including infomartion about builds 1.1 and 1.2
    Get-DBOPackage -Path c:\temp\myPackage.zip -Build 1.1, 1.2
     
    .NOTES
     
    #>

    [CmdletBinding(DefaultParameterSetName = 'Default')]
    Param(
        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 1)]
        [Alias('FileName', 'Name', 'Package')]
        [string[]]$Path,
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = 'Pipeline')]
        [object]$InputObject,
        [switch]$Unpacked
    )
    begin {

    }
    process {
        if ($PsCmdlet.ParameterSetName -eq 'Pipeline') {
            if ($InputObject) {
                if ($InputObject -is [DBOpsPackageBase]) {
                    Write-PSFMessage -Level Verbose -Message "Loading package file from pipelined object"
                    $InputObject
                }
                elseif ($InputObject -is [System.IO.FileInfo]) {
                    Write-PSFMessage -Level Verbose -Message "Loading package file from the archive $($InputObject.FullName)"
                    [DBOpsPackage]::new($InputObject.FullName)
                }
                elseif ($InputObject -is [String]) {
                    Write-PSFMessage -Level Verbose -Message "Loading package file from the archive $($InputObject)"
                    [DBOpsPackage]::new($InputObject)
                }
                else {
                    Stop-PSFFunction -EnableException $true -Message "The following object type is not supported: $($InputObject.GetType().Name). The only supported types are DBOpsPackage, FileInfo and String"
                    return
                }
            }
            else {
                Stop-PSFFunction -EnableException $true -Message "The object was not found"
                return
            }
        }
        elseif ($PsCmdlet.ParameterSetName -eq 'Default') {
            foreach ($pathItem in (Get-Item $Path -ErrorAction Stop)) {
                if ($Unpacked) {
                    if ($pathItem.PSIsContainer) {
                        $packageFileName = [DBOpsConfig]::GetPackageFileName()
                        $packageFile = Join-Path $pathItem.FullName $packageFileName
                        Write-PSFMessage -Level Verbose -Message "Loading package $packageFileName from folder $($pathItem.FullName)"
                        [DBOpsPackageFile]::new($packageFile)
                    }
                    else {
                        Write-PSFMessage -Level Verbose -Message "Loading package from the json file $pathItem"
                        [DBOpsPackageFile]::new($pathItem.FullName)
                    }
                }
                else {
                    Write-PSFMessage -Level Verbose -Message "Loading package file from the archive $pathItem"
                    [DBOpsPackage]::new($pathItem.FullName)
                }
            }
        }
        else {
            Write-PSFMessage -Level Verbose -Message "Creating new DBOps package $pFile"
            [DBOpsPackage]::new()
        }
    }
    end {

    }
}