2021-01-23 14:59:06 +00:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$VMName,
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$VSphereFQDN,
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$VSphereUsername,
|
|
|
|
[Parameter(Mandatory)]
|
2021-02-14 16:21:55 +00:00
|
|
|
[string]$VSpherePassword
|
2021-01-23 14:59:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
2021-02-13 19:16:31 +00:00
|
|
|
$GetVMSplat = @{
|
2021-02-14 12:22:34 +00:00
|
|
|
Name = "*$($VMName)*"
|
2021-02-13 19:16:31 +00:00
|
|
|
ErrorAction = 'SilentlyContinue'
|
|
|
|
}
|
|
|
|
If ([boolean](Get-VM @GetVMSplat)) {
|
|
|
|
$RemoveVMSplat = @{
|
2021-02-13 21:07:01 +00:00
|
|
|
VM = Get-VM @GetVMSplat
|
2021-02-13 19:16:31 +00:00
|
|
|
DeletePermanently = $True
|
|
|
|
Confirm = $False
|
|
|
|
ErrorAction = 'SilentlyContinue'
|
|
|
|
}
|
|
|
|
Remove-VM @RemoveVMSplat
|
2021-01-23 14:59:06 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 19:16:31 +00:00
|
|
|
Disconnect-VIServer * -Confirm:$False
|
2021-01-23 14:59:06 +00:00
|
|
|
|
2021-02-13 21:07:01 +00:00
|
|
|
$RemoveItemSplat = @{
|
2021-02-14 12:22:34 +00:00
|
|
|
Path = "/scratch/*"
|
2021-02-13 21:07:01 +00:00
|
|
|
Recurse = $True
|
|
|
|
Force = $True
|
|
|
|
Confirm = $False
|
|
|
|
}
|
2021-02-14 08:52:30 +00:00
|
|
|
Remove-Item @RemoveItemSplat
|