This may save some keystrokes but it’s not too useful. Let’s take this a bit further and create a virtual machine called MYVM with 2GB of memory.
New-VM-Name MYVM -MemoryGB 2
Again, not too bad at all but you’ll surely want more control over various configuration items than this. With New-VM you don’t have the option to configure things like, for example, the disk persistence mode. There’s no –Persistence parameter on New-VM. But, there is on Set-HardDisk. And, by using the PowerShell pipeline, we can do this all on a single line as one, cohesive command.
$newVM = New-VM -Name MYVM -MemoryGB 2
Get-HardDisk -VM $newVM | Set-HardDisk -Persistence ‘IndependentNonPersistent’
This would work but in large script, the code may get unwieldy. Why not have a single string of commands that builds your new VMs just as you’d like?
New-VM -Name MYVM -MemoryGB 2 | Get-HardDisk | Set-HardDisk -Persistence ‘IndependentPersistent’
Next time you’re creating a new VM and New-VM won’t cut it think about using the pipeline and sending that output directly to Set-VM or, in this case, hard disk-specific cmdlets for simpler scripts!