Hyper-V - Using 'New-Vm' cmdlet

Welcome Forums General PowerShell Q&A Hyper-V - Using 'New-Vm' cmdlet

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #93829

    Points: 0
    Rank: Member

    Hi all,

    I was following New-Vm to try creating a small function to automate the creation of VMs on Hyper-V.

    It's probably pretty terrible as I've just recently started using Posh, but:

    function New-Win10VM
        New-VM -NewVHDPath "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\$name" -NewVHDSizeBytes 100GB -BootDevice CD -ComputerName 'localhost' -Generation 2 -MemoryStartupBytes '2GB' -Name $name -Switchname 'Hyper V Ethernet'  

    Two questions:
    A) I could not set the value for -NewVHDSizeBytes nor -MemoryStartupBytes in GB as presented in the example.
    Error message:

    Cannot bind parameter 'MemoryStartupBytes'. Cannot convert value "2GB" to type "System.Int64". Error: "Input string was not in a correct format."

    Seems I had to translate it into bytes and then fill it into the script.
    B) Regarding -BootDevice:
    How can we set-it up to boot from a disk-image rather than a physical-cd? How do we specify the path of it?

    Thanks in advance for your help

  • #93864

    Points: 1,139
    Helping Hand
    Rank: Community Hero

    Nothing wrong with being a new PoSH user, but you really need to get a baseline understanding first before delving into to it to limit unnecessary pain and suffering. See resource at the end.

    Virtually, all the things you need to know about PoSH cmdlets, functions, features are in the built-in help files.
    Including copy, paste, use examples.

        # Get parameters, examples, full and Online help for a cmdlet or function
        (Get-Command -Name New-VM).Parameters
        Get-help -Name New-VM -Examples
        Get-help -Name New-VM -Full
        Get-help -Name New-VM -Online
        Get-Help about_*
        # All Help topics locations
        explorer "$pshome\$($Host.CurrentCulture.Name)"

    Or via the MS Docs site.


    Learning Resources

    Learn PowerShell: Microsoft Virtual Academy – Getting Started with Microsoft


    Microsoft Channe9


    Windows PowerShell Survival Guide


    And start with lots of examples.

    Looking at the .ps* files already on your system. There are bunches of them
    located here:


    Just make a copy of that and open in the PowerShell_ISE.exe and review them.
    Heck even in the ISE just hit CRTL+J to see a list of prebuilt snippets to
    review and understand.

    Learn to use the PowerShell console host
    Learn to use the PowerShell ISE
    Learn to use Visual Studio Code for PowerShell development and operations.

    Code editing. Redefined.
    Free. Open source. Runs everywhere

  • #94009

    Points: 0
    Rank: Member

    Hi postanote,

    Thank you for the resources!

    I've already finished the MVA's Powershell Beginner course with Hicks and Snover. I decided I needed some more practice with it before jumping straight into the Advanced course.
    I read 'Windows Powershell Networking guide' and 'Secrets of Powershell remoting' from the eBooks page and I'm slowly reading more.

    I found an answer for both my questions in here!

The topic ‘Hyper-V - Using 'New-Vm' cmdlet’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort