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
Hi,
foreach($vm in (Get-VM | Where-Object { ($_.PowerState -eq "PoweredOff") -and ($_.Guest.GuestId -eq "windows7Server64Guest") })) {
Enable-MemHotAdd $vm
Enable-vCpuHotAdd $vm
}
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
Hi,
foreach($vm in (Get-VM | Where-Object { ($_.PowerState -eq "PoweredOff") -and ($_.Guest.GuestId -eq "windows7Server64Guest") })) {
Enable-MemHotAdd $vm
Enable-vCpuHotAdd $vm
}
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
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"})
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
Thanks for the additional information Emanuel...much appreciated!