VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

Add windows os to filter

Hi

I'm trying to enable hot-add memory and hot-add cpu on windows 2008 vm's. How would Ia dd the OS to the filter?

Function Enable-MemHotAdd($vm){    

   $vmview = Get-vm $vm | Get-View   

   $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec      

   $extra = New-Object VMware.Vim.optionvalue    

   $extra.Key="mem.hotadd"   

   $extra.Value="true"   

   $vmConfigSpec.extraconfig += $extra     

   $vmview.ReconfigVM($vmConfigSpec)

}  

 

Function Enable-vCpuHotAdd($vm){    

   $vmview = Get-vm $vm | Get-View   

   $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec      

   $extra = New-Object VMware.Vim.optionvalue    

   $extra.Key="vcpu.hotadd"   

   $extra.Value="true"   

   $vmConfigSpec.extraconfig += $extra     

   $vmview.ReconfigVM($vmConfigSpec)

 

Foreach (

 

($vm in Get-VM | where {$_.PowerState -eq "PoweredOff"}

 

Enable-MemHotAdd

Enable-vCPUHotAdd

Thanks

0 Kudos
1 Solution

Accepted Solutions
EKardinal
Enthusiast
Enthusiast
Jump to solution

Hi,

foreach($vm in (Get-VM | Where-Object { ($_.PowerState -eq "PoweredOff") -and ($_.Guest.GuestId -eq "windows7Server64Guest") })) {

     Enable-MemHotAdd $vm

     Enable-vCpuHotAdd $vm

}

http://www.vmware.com/support/developer/converter-sdk/conv50_apireference/vim.vm.GuestOsDescriptor.G...

windows7Server64Guest is the equivalent to Microsoft Windows Server 2008 R2 (64-bit)

You could also use

$_.Guest.OSFullName

which should be the same as the Guest OS selection values. In the above case Microsoft Windows Server 2008 R2 (64-bit)

Regards

Emanuel

View solution in original post

0 Kudos
4 Replies
EKardinal
Enthusiast
Enthusiast
Jump to solution

Hi,

foreach($vm in (Get-VM | Where-Object { ($_.PowerState -eq "PoweredOff") -and ($_.Guest.GuestId -eq "windows7Server64Guest") })) {

     Enable-MemHotAdd $vm

     Enable-vCpuHotAdd $vm

}

http://www.vmware.com/support/developer/converter-sdk/conv50_apireference/vim.vm.GuestOsDescriptor.G...

windows7Server64Guest is the equivalent to Microsoft Windows Server 2008 R2 (64-bit)

You could also use

$_.Guest.OSFullName

which should be the same as the Guest OS selection values. In the above case Microsoft Windows Server 2008 R2 (64-bit)

Regards

Emanuel

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

Thanks Emanuel...that works!

I get confused sometimes when to use ) or }

I would have tried something like this:

(Get-VM | Where-Object {$_.PowerState -eq "PoweredOff" -and $_.Guest.GuestID -eq "Windows7Server64Guest"})

0 Kudos
EKardinal
Enthusiast
Enthusiast
Jump to solution

This would work, too.

I prefer to put every condition, I'd like to check, into round brackets.

This helps to differentiate the conditions from each other and also to build nested statements with multiple -and -or.

You can find a short overview about the bracket types with some basic tutorials and a short explanation: Windows PowerShell Brackets (Parenthesis), {braces}, [square] brackets.

Regards

Emanuel

AGFlora
Enthusiast
Enthusiast
Jump to solution

Thanks for the additional information Emanuel...much appreciated!

0 Kudos