Hi Everyone,
Can we pull the lists of VM having Memory reservation and CPU ? Also, how much Memory in GB having reservations and vCPU.
thanks
vmk
Try like this
Get-Cluster -PipelineVariable cluster |
ForEach-Object -Process {
$report = Get-VM -Location $cluster -PipelineVariable vm |
Get-VMResourceConfiguration |
where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |
select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={$vm.Name}},
CpuReservationMhz,MemReservationGB
$report += "" | Select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={'Total'}},
@{N='CpuReservationMhz';E={($report | Measure-Object -Property CpuReservationMhz -Sum).Sum}},
@{N='MemReservationGB';E={($report | Measure-Object -Property MemReservationGB -Sum).Sum}}
$report
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A quick small post to list the memory limits on the VM and set it back to unlimited using a PowerCLI
To list the VM’s which have memory limit configured
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne ‘-1’} | Select VM,MemLimitMB
And to set it to unlimited
Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne ‘-1’} | Set-VMResourceConfiguration -MemLimitMB $null
For CPU the attributes to be changed to CpuLimitMhz
Thank you. Since we have a large environment so trying to pull the lists for around 15 VM's which is having reservations.
Try like this
Get-VM -PipelineVariable vm |
Get-VMResourceConfiguration |
where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |
select @{N='VM';E={$vm.Name}},
CpuReservationMhz,MemReservationGB
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Can we pull reservation at Cluster and Total memory reserved ( Sum)
Thanks
vmk
Try like this
Get-Cluster -PipelineVariable cluster |
ForEach-Object -Process {
$report = Get-VM -Location $cluster -PipelineVariable vm |
Get-VMResourceConfiguration |
where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |
select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={$vm.Name}},
CpuReservationMhz,MemReservationGB
$report += "" | Select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={'Total'}},
@{N='CpuReservationMhz';E={($report | Measure-Object -Property CpuReservationMhz -Sum).Sum}},
@{N='MemReservationGB';E={($report | Measure-Object -Property MemReservationGB -Sum).Sum}}
$report
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Sorry, to say some goof up happened, it's not picking the right cluster name. For every VM's showing in almost all the cluster though the VM is mapped to single cluster.
Thanks
vmk
Yes, you are right, I forgot the Location parameter on the Get-VM cmdlet.
I updated the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok LucD,
I ran once again the scripts but it throws an error
PS C:\temp> .\Memory_reservation.ps1
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:23 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:23 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:23 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
thanks
vmk
Even output are jumbled up.
Which PowerShell version are you using?
Do a $PSVersionTable
As an alternative, try like this
Get-Cluster -PipelineVariable cluster |
ForEach-Object -Process {
$report = @()
$report += Get-VM -Location $cluster -PipelineVariable vm |
Get-VMResourceConfiguration |
where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |
select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={$vm.Name}},
CpuReservationMhz,MemReservationGB
$report += "" | Select @{N='Cluster';E={$cluster.Name}},
@{N='VM';E={'Total'}},
@{N='CpuReservationMhz';E={($report | Measure-Object -Property CpuReservationMhz -Sum).Sum}},
@{N='MemReservationGB';E={($report | Measure-Object -Property MemReservationGB -Sum).Sum}}
$report
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I'm using power Cli version 11. Will check belwo script and update you.
thanks
vmk
I meant the PowerShell version (check by displaying what is in $PSVersionTable).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
LucD,
After running the alternative script, please find the output
PS C:\temp> .\Memory_reservation.ps1
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:22 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:22 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Memory_reservation.ps1:22 char:5
+ $report += "" | Select @{N='Cluster';E={$cluster.Name}},
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
I made a small change to the latest version of the script.
Can you give that one a try?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, it's working now. No error this time.
I suspect it was due to the fact that you had a cluster with 1 VM that has reservations.
That way the array $report became a scalar instead of an array, and then the += to add the Total wasn't working anymore.
By changing the = on the Select to a +=, we made sure that $report stayed an array.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD !!