2021-01-24 08:26:53 +00:00
|
|
|
[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
|
|
|
|
|
2021-04-10 13:32:31 +00:00
|
|
|
$GetVMSplat = @{
|
|
|
|
Name = "*$($VMName)*"
|
|
|
|
ErrorAction = 'SilentlyContinue'
|
|
|
|
}
|
|
|
|
If ([boolean](Get-VM @GetVMSplat)) {
|
|
|
|
$RemoveVMSplat = @{
|
|
|
|
VM = Get-VM @GetVMSplat
|
|
|
|
DeletePermanently = $True
|
|
|
|
Confirm = $False
|
|
|
|
ErrorAction = 'SilentlyContinue'
|
|
|
|
}
|
|
|
|
Remove-VM @RemoveVMSplat
|
2021-01-24 08:26:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 13:32:31 +00:00
|
|
|
Disconnect-VIServer * -Confirm:$False
|
2021-01-24 08:26:53 +00:00
|
|
|
|
2021-04-10 13:32:31 +00:00
|
|
|
$RemoveItemSplat = @{
|
|
|
|
Path = "/scratch/*"
|
|
|
|
Recurse = $True
|
|
|
|
Force = $True
|
|
|
|
Confirm = $False
|
|
|
|
}
|
|
|
|
Remove-Item @RemoveItemSplat
|