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

    process
    {
        foreach ($snip in $Name)
        {
            $snip = $snip -replace 'AutomatedLab\..*\.'
            $schnippet = Get-LabSnippet -Name $snip
            if (-not $schnippet)
            {
                Write-PSFMessage -Level Warning -Message "Snippet $snip not found"
                break
            }

            $location = Get-PSFConfigValue -FullName AutomatedLab.Recipe.SnippetStore
            $filePath = Join-Path -Path $location -ChildPath "$($schnippet.Name).ps1"
            $metaPath = Join-Path -Path $location -ChildPath "$($schnippet.Name).psd1"

            Remove-Item -Path $filePath, $metaPath -ErrorAction SilentlyContinue
        }
    }
}