Packer.Images/scripts/Remove-Resources.ps1
djpbessems 961624998b
Some checks failed
continuous-integration/drone/push Build is failing
Fix path;Add conditional
2021-02-13 20:16:31 +01:00

46 lines
1.1 KiB
PowerShell

[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string]$VMName,
[Parameter(Mandatory)]
[string]$VSphereFQDN,
[Parameter(Mandatory)]
[string]$VSphereUsername,
[Parameter(Mandatory)]
[string]$VSpherePassword
)
$PowerCliConfigurationSplat = @{
Scope = 'User'
ParticipateInCEIP = $False
Confirm = $False
InvalidCertificateAction = 'Ignore'
}
Set-PowerCLIConfiguration @PowerCliConfigurationSplat | Out-Null
$ConnectVIServerSplat = @{
Server = $VSphereFQDN
User = "$VSphereUsername"
Password = "$VSpherePassword"
WarningAction = 'SilentlyContinue'
}
Connect-VIServer @ConnectVIServerSplat | Out-Null
$GetVMSplat = @{
VM = "$($VMName)*"
ErrorAction = 'SilentlyContinue'
}
If ([boolean](Get-VM @GetVMSplat)) {
$RemoveVMSplat = @{
VM = "$($VMName)*"
DeletePermanently = $True
Confirm = $False
ErrorAction = 'SilentlyContinue'
}
Remove-VM @RemoveVMSplat
}
Disconnect-VIServer * -Confirm:$False
# Delete scratch folder contents