Remove-Config.ps1
function Remove-Config { <# .Synopsis Gets stored configurations .Description Gets stored DSC configurations. .Example Remove-Config "MySavedConfig" .Link Get-Config .Link Save-Config .Link Use-Config #> [OutputType([Nullable])] [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( # The name of the configuration [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true)] [string[]]$Name ) process { $configRoots = Join-Path (Join-Path $env:ProgramData "Start-Automating") "cFg" foreach ($n in $Name) { $Filter = if ($Name) { "$name.config.ps1" } else { "*.config.ps1" } $files = $configRoots | Get-ChildItem -ErrorAction SilentlyContinue -Filter $Filter foreach ($_ in $files) { #region Confirm and Remove if ($PSCmdlet.ShouldProcess("Remove $($_.Fullname)")) { Remove-Item -Force -Path $_.Fullname # Remove associated notes file, if one existed $notePath = $_.FullName -ireplace '\.config\.ps1', '.config.notes.txt' Remove-Item -Force -Path $notePath -ErrorAction SilentlyContinue } #endregion Confirm and Remove } } } } |