Remove-OSCustomizationSpec
VMware: Removes an OS customization specification
#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding(DefaultParameterSetName = "ByName")]
Param(
[Parameter(Mandatory = $true, ParameterSetName = "ByName")]
[Parameter(Mandatory = $true, ParameterSetName = "ById")]
[string]$VIServer,
[Parameter(Mandatory = $true, ParameterSetName = "ByName")]
[Parameter(Mandatory = $true, ParameterSetName = "ById")]
[pscredential]$VICredential,
[Parameter(Mandatory = $true, ParameterSetName = "ById")]
[string]$ID,
[Parameter(Mandatory = $true, ParameterSetName = "ByName")]
[string]$SpecName
)
Process {
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$cmdArgs = @{ ErrorAction = 'Stop'; Server = $vmServer }
if ($PSCmdlet.ParameterSetName -eq "ById") { $spec = Get-OSCustomizationSpec @cmdArgs -ID $ID -ErrorAction Stop }
else { $spec = Get-OSCustomizationSpec @cmdArgs -Name $SpecName -ErrorAction Stop }
if ($null -eq $spec) { throw "OS customization specification not found" }
$null = Remove-OSCustomizationSpec @cmdArgs -OSCustomizationSpec $spec -Confirm:$false -ErrorAction Stop
[PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Status = "Success"; Message = "OS customization specification successfully removed" }
}
catch { throw }
finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}IP address or DNS name of the vSphere server
PSCredential object for authenticating with the server
ID of the OS customization specification
Name of the OS customization specification