Resolved issues with deleting VM on a remote computer

This commit is contained in:
Christopher York 2015-03-30 11:42:42 -06:00
parent a2def5381f
commit 732adfd8cf

View file

@ -504,7 +504,7 @@ namespace WebsitePanel.Providers.Virtualization
if (vm.State != VirtualMachineState.Saved && vm.State != VirtualMachineState.Off) if (vm.State != VirtualMachineState.Saved && vm.State != VirtualMachineState.Off)
throw new Exception("The virtual computer system must be in the powered off or saved state prior to calling Destroy method."); throw new Exception("The virtual computer system must be in the powered off or saved state prior to calling Destroy method.");
// Delete network adapters and network switchesw // Delete network adapters and network switches
foreach (var networkAdapter in vm.Adapters) foreach (var networkAdapter in vm.Adapters)
{ {
NetworkAdapterHelper.Delete(PowerShell, vm.Name, networkAdapter); NetworkAdapterHelper.Delete(PowerShell, vm.Name, networkAdapter);
@ -516,7 +516,7 @@ namespace WebsitePanel.Providers.Virtualization
Command cmdSet = new Command("Remove-VM"); Command cmdSet = new Command("Remove-VM");
cmdSet.Parameters.Add("Name", vm.Name); cmdSet.Parameters.Add("Name", vm.Name);
cmdSet.Parameters.Add("Force"); cmdSet.Parameters.Add("Force");
PowerShell.Execute(cmdSet, false, true); PowerShell.Execute(cmdSet, true, true);
return JobHelper.CreateSuccessResult(ReturnCode.JobStarted); return JobHelper.CreateSuccessResult(ReturnCode.JobStarted);
} }
@ -782,10 +782,11 @@ namespace WebsitePanel.Providers.Virtualization
Command cmd = new Command("Get-VMSwitch"); Command cmd = new Command("Get-VMSwitch");
if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName); // Not needed as the PowerShellManager adds the computer name
//if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type); if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
Collection<PSObject> result = PowerShell.Execute(cmd, false, true); Collection<PSObject> result = PowerShell.Execute(cmd, true, true);
foreach (PSObject current in result) foreach (PSObject current in result)
{ {