Skip to content

Commit

Permalink
Merge pull request #38 from h4xhor/AUSTA-304
Browse files Browse the repository at this point in the history
AUSTA-304: Bug in Step "Delete VM with Windows Worker"
  • Loading branch information
jarrodchesney authored Nov 15, 2023
2 parents 7e6ea84 + 36a19ce commit 9f5e77b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
21 changes: 9 additions & 12 deletions docs/Build-Virtual-Machine-on-ESXi-with-Windows-Worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -629,25 +629,22 @@ <h3 id="deletevmwithwindowsworker">
exit 1
}

$existing = Get-VM &quot;{newVmNode.fqn}&quot;
if ( $existing.count -eq 1 ) {
} else {
$existing = Get-VM &quot;{newVmNode.hostname}&quot;
}
$exists = Get-VM &quot;{newVmNode.fqn}&quot; -ErrorAction SilentlyContinue
if ( -Not $exists ) {
&quot;The VM doesn&#x27;t exist&quot;
} else {
$VM = Get-VM &quot;{newVmNode.fqn}&quot;

if ( $existing.count -eq 1 ) {
if ( $existing.PowerState -eq &quot;PoweredOn&quot; ) {
if ( $VM.PowerState -eq &quot;PoweredOn&quot; ) {
&quot;Stopping the VM&quot;
Stop-VM -VM $existing -Confirm:$false
Stop-VM -VM $VM -Confirm:$false
} else {
&quot;The VM is off&quot;
}

&quot;Removing the VM&quot;
Remove-VM -DeleteFromDisk -VM $existing -Confirm:$false

} else {
&quot;The VM doesn&#x27;t exist&quot;
Remove-VM -DeleteFromDisk -VM $VM -Confirm:$false

}
</code>
</pre>
Expand Down
21 changes: 9 additions & 12 deletions docs/Delete-the-Virtual-Machine-on-ESXi-with-Windows-Worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,25 +369,22 @@ <h3 id="deletevmwithwindowsworker">
exit 1
}

$existing = Get-VM &quot;{newVmNode.fqn}&quot;
if ( $existing.count -eq 1 ) {
} else {
$existing = Get-VM &quot;{newVmNode.hostname}&quot;
}
$exists = Get-VM &quot;{newVmNode.fqn}&quot; -ErrorAction SilentlyContinue
if ( -Not $exists ) {
&quot;The VM doesn&#x27;t exist&quot;
} else {
$VM = Get-VM &quot;{newVmNode.fqn}&quot;

if ( $existing.count -eq 1 ) {
if ( $existing.PowerState -eq &quot;PoweredOn&quot; ) {
if ( $VM.PowerState -eq &quot;PoweredOn&quot; ) {
&quot;Stopping the VM&quot;
Stop-VM -VM $existing -Confirm:$false
Stop-VM -VM $VM -Confirm:$false
} else {
&quot;The VM is off&quot;
}

&quot;Removing the VM&quot;
Remove-VM -DeleteFromDisk -VM $existing -Confirm:$false

} else {
&quot;The VM doesn&#x27;t exist&quot;
Remove-VM -DeleteFromDisk -VM $VM -Confirm:$false

}
</code>
</pre>
Expand Down
21 changes: 9 additions & 12 deletions steps/deletevmwithwindowsworker/script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ if ($? -eq $false) {
exit 1
}

$existing = Get-VM "{newVmNode.fqn}"
if ( $existing.count -eq 1 ) {
} else {
$existing = Get-VM "{newVmNode.hostname}"
}
$exists = Get-VM "{newVmNode.fqn}" -ErrorAction SilentlyContinue
if ( -Not $exists ) {
"The VM doesn't exist"
} else {
$VM = Get-VM "{newVmNode.fqn}"

if ( $existing.count -eq 1 ) {
if ( $existing.PowerState -eq "PoweredOn" ) {
if ( $VM.PowerState -eq "PoweredOn" ) {
"Stopping the VM"
Stop-VM -VM $existing -Confirm:$false
Stop-VM -VM $VM -Confirm:$false
} else {
"The VM is off"
}

"Removing the VM"
Remove-VM -DeleteFromDisk -VM $existing -Confirm:$false

} else {
"The VM doesn't exist"
Remove-VM -DeleteFromDisk -VM $VM -Confirm:$false

}

0 comments on commit 9f5e77b

Please sign in to comment.