vSekar Blog

Getting Hands Dirty With Technology

  • About vSekar
  • Get in Touch
  • Facebook
  • Twitter
  • LinkedIn
Posts and Views are my Own
You are here: Home / powercli / How to Allocate Resources to VMs while Creating it.

How to Allocate Resources to VMs while Creating it.

August 20, 2016 By v

How to Allocate Resources to VMs while Creating it.
By using VMware PowerCLI, you may spun up a new Virtual Machine using the New-VM cmdlet.
You have to specify nothing but your VM name

 

New VM
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!

Thank you

Adam Bertram

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

Filed Under: powercli, Powershell