functions/Remove-DBOBuild.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
Function Remove-DBOBuild {
    <#
    .SYNOPSIS
    Removes one or more builds from the DBOps package
     
    .DESCRIPTION
    Remove specific list of builds from the existing DBOps package keeping all other parts of the package intact
     
    .PARAMETER Path
    Path to the existing DBOpsPackage.
    Aliases: Name, FileName, Package
     
    .PARAMETER Build
    One or more builds to remove from the 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
    # Removes builds 1.1 and 1.2 from the package
    Remove-DBOBuild -Path c:\temp\myPackage.zip -Build 1.1, 1.2
 
    .EXAMPLE
    # Removes all 1.* builds from the package
    $builds = (Get-DBOPackage c:\temp\myPackage.zip).Builds
    $builds.Build | Where { $_ -like '1.*' } | Remove-DBOBuild -Path c:\temp\myPackage.zip
     
    .NOTES
     
    #>

    [CmdletBinding(SupportsShouldProcess = $true)]
    Param(
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            Position = 1)]
        [Alias('FileName', 'Name', 'Package')]
        [string]$Path,
        [Parameter(Mandatory = $true,
            Position = 2)]
        [string[]]$Build
    )
    begin {
        
    }
    process {
        Write-PSFMessage -Level Verbose -Message "Loading package information from $Path"
        if ($package = Get-DBOPackage -Path $Path) {
            foreach ($currentBuild in $Build) {
                #Verify that build exists
                if ($currentBuild -notin $package.EnumBuilds()) {
                    Write-Warning "Build $currentBuild not found in the package, skipping."
                    continue
                }
            
                Write-PSFMessage -Level Verbose -Message "Removing $currentBuild from the package object"
                $package.RemoveBuild($currentBuild)

                if ($pscmdlet.ShouldProcess($package, "Saving changes to the package")) {
                    $package.Alter()
                }
            }
        }
    }
    end {
        
    }
}