Giter Club home page Giter Club logo

hyperv.net's People

Contributors

icnocop avatar jscarle avatar muskankhedia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperv.net's Issues

How to add existing VHD/VHDX to VM?

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?

examples

Hello, do you have any examples of using this library? Can you view the information about Hyper-V virtual machine! thank you

Change number of processors on an existing VM

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)));
        }

Resource pool being null

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?

TPM Enabled

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.