Public/Remove-LabRecipe.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
function Remove-LabRecipe
{
    [CmdletBinding(SupportsShouldProcess)]
    param
    (
        [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, ParameterSetName = 'ByName')]
        [string]
        $Name,

        [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'ByRecipe')]
        [System.Management.Automation.PSCustomObject]
        $Recipe
    )

    begin
    {
        $recipePath = Join-Path -Path $HOME -ChildPath 'automatedLab\recipes'
    }

    process
    {        
        if (-not $Name)
        {
            $Name = $Recipe.Name
        }
        
        Get-ChildItem -File -Filter *.json -Path $recipePath | Where-Object -Property BaseName -eq $Name | Remove-Item
    }
}