public/Delete-OSDeployBootProfilePreview.ps1
|
#Requires -PSEdition Core #Requires -Version 7.4 function Delete-OSDeployBootProfilePreview { <# .SYNOPSIS Deletes an OSDeploy Boot profile .DESCRIPTION Deletes the selected profile directory and all profile-local content only when Force is specified. Generated boot media, shared Boot-Assets content, and cached content are not removed. The deletion also honors WhatIf and Confirm. .PARAMETER ProfileName Specifies the exact canonical name of an existing profile. Values tab-complete from architecture-specific profile directories containing osdeployboot.json. .PARAMETER Force Enables deletion. When omitted, the command writes a warning and makes no change. .EXAMPLE PS> Delete-OSDeployBootProfilePreview -ProfileName 'Contoso-amd64' Writes a warning and leaves the profile unchanged because Force was omitted. .EXAMPLE PS> Delete-OSDeployBootProfilePreview -ProfileName 'Contoso-amd64' -Force Deletes the Contoso-amd64 profile directory. .INPUTS None. This function does not accept pipeline input. .OUTPUTS None. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-09-03 Deletion is recursive and cannot be undone by this command. .LINK New-OSDeployBootProfilePreview .LINK Update-OSDeployBootProfilePreview #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] param ( [Parameter(Mandatory)] [ArgumentCompleter({ param($commandName, $parameterName, $wordToComplete) $ProfilePath = Join-Path $env:ProgramData 'OSDeployCore\boot-assets\osdeployboot-profiles' Get-ChildItem -LiteralPath $ProfilePath -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "$wordToComplete*" -and (Test-Path -LiteralPath (Join-Path $_.FullName 'osdeployboot.json') -PathType Leaf) } | Sort-Object Name | ForEach-Object { $CompletionText = if ($_.Name -match '\s') { "'$($_.Name.Replace("'", "''"))'" } else { $_.Name } [System.Management.Automation.CompletionResult]::new( $CompletionText, $_.Name, [System.Management.Automation.CompletionResultType]::ParameterValue, $_.FullName ) } })] [System.String] $ProfileName, [System.Management.Automation.SwitchParameter] $Force ) Write-Verbose "[$($MyInvocation.MyCommand.Name)] Start" if ([System.String]::IsNullOrWhiteSpace($ProfileName)) { throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] ProfileName cannot be empty." } $SelectedProfile = Select-BuildOSDeployBootProfile -Name $ProfileName -SkipPathValidation -SkipTokenMigration if (-not $SelectedProfile) { throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Build profile was not found or could not be read: $ProfileName" } if (-not $Force) { Write-Warning "[$(Get-Date -Format s)] Force is required to delete the OSDeploy Boot profile '$ProfileName'." return } $ProfilePath = Split-Path -Path $SelectedProfile.FullName -Parent if ($PSCmdlet.ShouldProcess($ProfilePath, 'Delete OSDeploy Boot profile')) { Remove-Item -LiteralPath $ProfilePath -Recurse -Force -ErrorAction Stop } Write-Verbose "[$($MyInvocation.MyCommand.Name)] End" } |