jscarle / hyperv.net Goto Github PK
View Code? Open in Web Editor NEWSimple Hyper-V Virtual Machine Management
License: MIT License
Simple Hyper-V Virtual Machine Management
License: MIT License
How is it possible to add an existing VHD/VHDX to a virtual machine?
I can create a Virtual Hard Drive and subsequently a Virtual Hard Disk, but I cannot point it to an existing path?
Can you provide an example of how do do this?
Hello, do you have any examples of using this library? Can you view the information about Hyper-V virtual machine! thank you
Hi,
I am so happy that I found this project. I have been banging my head the last week.
I have already imported a VM, and now I want to change the number of processors of the virtual machine. I can only find this in the CreateVirtualMachine (in VMMS_public.cs).
My question is: Is there a way to change the number of processors on an existing VM?
(I see that this is relates to another "issue" here (#7), where they want to change something on an existing VM).
Comment: The reason for changing in an existing VM is, that I use TPM, and the TPM is imported and checked against the Host Guardian Service. So it will not work for me to make a new VM, unless I can import only the TPM (I don't thisnk that is possible).
I think I just found a solution (I used the code from https://github.com/jscarle/HyperV.NET):
// Main program:
ManagementObject systemSettings = CreateSettings(Settings.System);
ManagementObject virtualMachine = GetVm.GetVmClass.GetVm(".", "MyVm");
ManagementObject processorSettings = GetRelatedSettings(systemSettings, Settings.Processor);
processorResource["VirtualQuantity"] = 4;
ModifyResourceSettings(new ManagementObject[] { processorSettings }, out _);
I used these functions from https://github.com/jscarle/HyperV.NET. But may have changed them a bit. Remember to include the WMI_extensions file form the repo (for ToStringArray() and more):
// Extra functions and stuff:
static internal ManagementObject CreateSettings(Settings settings)
{
string hostname = ".";
System.Management.ManagementScope virtualizationScope = new System.Management.ManagementScope(@"\\" + hostname + @"\root\virtualization\v2", null);
using (ManagementClass managementClass = new ManagementClass(SettingsClass(settings)))
{
managementClass.Scope = virtualizationScope;
return managementClass.CreateInstance();
}
}
static internal void ModifyResourceSettings(ManagementObject[] resourceSettings, out ManagementObject[] resultingResourceSettings)
{
string hostname = ".";
System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + hostname + @"\root\virtualization\v2", null);
using (ManagementObject managementService = WmiUtilities.GetVirtualMachineManagementService(scope))
using (ManagementBaseObject inputParameters = managementService.GetMethodParameters("ModifyResourceSettings"))
{
inputParameters["ResourceSettings"] = resourceSettings.ToStringArray();
using (ManagementBaseObject outputParameters = managementService.InvokeMethod("ModifyResourceSettings", inputParameters, null))
{
WmiUtilities.ValidateOutput(outputParameters, scope);
resultingResourceSettings = ((string[])outputParameters["ResultingResourceSettings"]).ToObjectArray();
}
}
}
internal static ManagementObject GetRelatedSettings(ManagementObject instance, Settings settings)
{
return WmiUtilities.GetFirstObjectFromCollection(instance.GetRelated(SettingsClass(settings)));
}
Is there any function in the VMMS class, that will help to fetch the MAC address of the recently created VM?
am trying to create a virtual machine but resourcePool is being null for resourceSubType = "Microsoft:Hyper-V:Memory" and resourcePoolClass = "Msvm_ResourcePool":-
ObjectQuery query = new ObjectQuery($"SELECT * FROM {resourcePoolClass} WHERE ResourceSubType = "{resourceSubType}" AND Primordial = True");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(virtualizationScope, query))
using (ManagementObject resourcePool = searcher.Get().First())
Please how may I resolve this issue?
NET 5.0 reached the end of support on May 10, 2022.
Further, Microsoft will no longer provide updates including security fixes, or technical support for .NET5.0. It is strongly recommended to migrate applications to .NET 6.0.
For more info, please refer to the official announcement: https://devblogs.microsoft.com/dotnet/dotnet-5-end-of-support-update/
Hello, may I ask how to call the vhdx template when creating a VM, and then use the password configured by myself as the login password? For example, I place the vhdx template of Centos7.9 in a directory, obtain the template name during installation, install the system, and use the system password defined by myself after installation
HyperV.NET/.github/workflows/main.yml
Line 54 in 65cbaa0
The AssemblyInfo.cs does in fact get updated as reflected in the build, but the repository is unchanged.
Enabling Trusted Platform Module (TPM) flag by setting value to True
did not enable TPM on Hyper-V machine.
Code used:
vmDefinition.NetworkAdapters[0].VirtualSwitch = "Default Switch";
vmDefinition.AutomaticStop.Action = AutomaticStopAction.TurnOff;
vmDefinition.Checkpoints.Type = CheckpointType.None; // do not use checkpoints in dev
vmDefinition.AutomaticStart.Action = AutomaticStartAction.Nothing;
vmDefinition.Security.TrustedPlatformModule = true; // enable TPM
Reading through the source files, it indicated to me that this would be the correct way to enable. The code above would enable SecureBoot by default.
Pursuant to this, I did adjust the code to include this SecureBoot first then re-run as follows:
vmDefinition.NetworkAdapters[0].VirtualSwitch = "Default Switch";
vmDefinition.AutomaticStop.Action = AutomaticStopAction.TurnOff;
vmDefinition.Checkpoints.Type = CheckpointType.None; // do not use checkpoints in dev
vmDefinition.AutomaticStart.Action = AutomaticStartAction.Nothing;
vmDefinition.Security.SecureBoot = true; // enable SecureBoot
vmDefinition.Security.TrustedPlatformModule = true; // enable TPM
Now when I check the Hyper-V machine manually, I can see the TPM is enabled.
This was strange as although the SecureBoot value was True
. However by manually setting this flag, I was finally able to force enable TPM too.
Is there any feature to fetch the list of virtual machines available in the current host machine?
After a VM has been created using the VMMS service, how could we start the machine automatically?
How to list all virtual machines?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.