VMware Cloud Community
simonadams
Contributor
Contributor

Removing limits from all VM's in a single cluster

Hi all

I've found a script that does exactly what I want here -> http://get-admin.com/blog/?p=620

But how do I change this line to select only VM's in cluster xxx;

Foreach ($VM in get-vm | get-view) {

?

I'm still trying to get my head around the syntax so would appreciate any help.

Many thanks


Simon

Reply
0 Kudos
11 Replies
LucD
Leadership
Leadership

Like this

Foreach ($VM in (Get-Cluster MyCluster | get-vm | get-view)) {


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

simonadams
Contributor
Contributor

Thats what I thought but the cluster name is VDS - SDC02. If I put it in without quotes it syntax errors on the '-' and if I put quotes around it it finds no VM's ?

Reply
0 Kudos
simonadams
Contributor
Contributor

Could the problem be that all VM's are within resource pools within the cluster ?

Reply
0 Kudos
aevrov
VMware Employee
VMware Employee

No, since you don't specify -NoRecursion.

Do you get the cluster you want? First try the <Get-Cluster -Name "VDS - SDC02"> part, and see if it returns the cluster.

Regards,

-Angel

simonadams
Contributor
Contributor

Yes it finds the cluster okay;

[vSphere PowerCLI] E:\> Get-Cluster -Name "VDS - SDC02"

Name                           HAEnabled  HAFailover DrsEnabled DrsAutomationLe
                                          Level                 vel
----                           ---------  ---------- ---------- ---------------
VDS - SDC02                    True       1          True       FullyAutomated

So I guess its not finding VM's with limits ?  I assume the script linked to above was complete - I've just added a VI server connect... ?

Reply
0 Kudos
aevrov
VMware Employee
VMware Employee

If you get the cluster ok, it should return the VMs also.. I don't know what else to say.., start a vClient and check if the VMs are where you expect..

Regards,

-Angel

Reply
0 Kudos
simonadams
Contributor
Contributor

Mmm... vm's are definitely all there.

I tried the brute force approach of;

Get-Cluster "VDS - SDC02" | Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemLimitMB $null -CpuLimitMhz $null

but that comes back with;

Get-VMResourceConfiguration : Object reference not set to an instance of an obj
ect.
At line:1 char:65
+ Get-Cluster "VDS - SDC02" | Get-VM | Get-VMResourceConfiguration <<<<  | Set-
VMResourceConfiguration -MemLimitMB $null -CpuLimitMhz $null
    + CategoryInfo          : NotSpecified: (:) [Get-VMResourceConfiguration],
    NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,VMware.VimAutomati
   on.Commands.GetVMResourceConfiguration

and;

Get-Cluster "VDS - SDC02" | Get-VM | `
Get-VMResourceConfiguration | `
Where-Object {$_.MemLimitMB -ne -1 -or $_.CpuLimitMhz -ne -1} | `
Set-VMResourceConfiguration -MemLimitMB $null -CpuLimitMhz $Null

Comes back with;

Get-VMResourceConfiguration : Object reference not set to an instance of an obj
ect.
At line:2 char:28
+ Get-VMResourceConfiguration <<<<  | `
    + CategoryInfo          : NotSpecified: (:) [Get-VMResourceConfiguration],
    NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,VMware.VimAutomati
   on.Commands.GetVMResourceConfiguration

But can't work out what is causing either...

Not doing so well with this one...

Reply
0 Kudos
simonadams
Contributor
Contributor

Could the templates in the cluster be causing all this ?

Reply
0 Kudos
simonadams
Contributor
Contributor

From this thread - http://communities.vmware.com/thread/256710 it looks like there is a bug in Get-VMResourceConfiguration that could be causing these latter errors (as all vm's have specific share values set daily.

Do I need to update powerCLI if thats the issue ?

And this still doesn;t explain the original issue with the script...

Reply
0 Kudos
simonadams
Contributor
Contributor

I've found a way that works!

$spec = new-object VMware.Vim.VirtualMachineConfigSpec

$spec.MemoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo

$spec.MemoryAllocation.Limit = -1

$spec.CpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo

$spec.CpuAllocation.Limit = -1

Get-Cluster "VDS - SDC02" | Get-VM | Get-View | %{$_.ReconfigVM_Task($spec)}

Still a bit confused about the other problems but thanks all for your help..

Reply
0 Kudos
admin
Immortal
Immortal

Hi,

Yes, it's good to use the latest version of PowerCLI 4.1.1 which you can download from here -> http://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli

Can you confirm that after updating PowerCLI the expression " Get-Cluster ... | Get-VM | Get-VMResourceConfiguration" does not throw error?

Thanks,

Vitali

PowerCLI team

Reply
0 Kudos