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?
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)"
Learn PowerShell: Microsoft Virtual Academy – Getting Started with Microsoft
PowerShell.
'mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276'
Microsoft Channe9
'channel9.msdn.com/Series/GetStartedPowerShell3'
'channel9.msdn.com/Search?term=powershell#ch9Search&lang-en=en&pubDate=year'
Youtube
'youtube.com/results?search_query=beginnign+powershell'
Windows PowerShell Survival Guide
'social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspxStart-Process'
eBooks...
'blogs.technet.microsoft.com/pstips/2014/05/26/free-powershell-ebooks'
'idera.com/resourcecentral/whitepapers/powershell-ebook'
'powershell.org/ebooks'
And start with lots of examples.
'powershellgallery.com'
'gallery.technet.microsoft.com/scriptcenter/site/requests'
'technet.microsoft.com/en-us/scriptcenter/bb410849.aspx'
Looking at the .ps* files already on your system. There are bunches of them
located here:
C:\Windows\System32\WindowsPowerShell\v1.0
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.
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!
Thanks