VMware Cloud Community
online11
Contributor
Contributor
Jump to solution

Perennially Reserved by Cluster

Hi everyone, I am looking for a script that marks RDM disks as perennially reserved by cluster name. It will set perennially reserve all RDM disks under a specific cluster. There are some scripts available but it refers to VM Name. I need a powercli script that is independent from VM names. Thanks in advance, much appreciated.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this.

Note that I used PowerCLI 6.3, to have the V2 switch on the Get-EsxCli cmdlet.

$clusterName = 'MyCluster'

$cluster = Get-Cluster -Name $clusterName

$luns = Get-VM -Location $cluster | Get-HardDisk |

where{$_.DiskType -match '^Raw'} | Select -ExpandProperty ScsiCanonicalName

Get-VMHost -Location $cluster | %{

    $esxcli = Get-EsxCli -VMHost $_ -V2

    $esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Device} | %{

        $params = @{

            device = $_.Device

            perenniallyreserved = $true

        }

        $esxcli.storage.core.device.setconfig.Invoke($params)

    }

}


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

View solution in original post

11 Replies
LucD
Leadership
Leadership
Jump to solution

Let me see if I get the question correctly, you want a script that checks all VMs in a cluster, and if a VM has a RDM, you want the script to set the LUN behind that RDM as perennially reserved.

Is my interpretation correct?


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

0 Kudos
online11
Contributor
Contributor
Jump to solution

Hi Luc, Thanks for prompt reply. You are correct. I want to mark all RDM disks perennially reserved under a specific HA cluster. Can I specifically target a clustername to make it all RDMs under as Perennially reserve? Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this.

Note that I used PowerCLI 6.3, to have the V2 switch on the Get-EsxCli cmdlet.

$clusterName = 'MyCluster'

$cluster = Get-Cluster -Name $clusterName

$luns = Get-VM -Location $cluster | Get-HardDisk |

where{$_.DiskType -match '^Raw'} | Select -ExpandProperty ScsiCanonicalName

Get-VMHost -Location $cluster | %{

    $esxcli = Get-EsxCli -VMHost $_ -V2

    $esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Device} | %{

        $params = @{

            device = $_.Device

            perenniallyreserved = $true

        }

        $esxcli.storage.core.device.setconfig.Invoke($params)

    }

}


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

online11
Contributor
Contributor
Jump to solution

Hi Luc, I got the error below when I run this script. Thanks a lot. You cannot call a method on a null-valued expression. At C:\script1.ps1:7 char:5 +    $esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Devi ce} ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~     + CategoryInfo          : InvalidOperation: (:) [], RuntimeException     + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At C:\script1.ps1:7 char:5 +    $esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Devi ce} ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version are you running (do a Get-PowerCLIVersion)?

Can I see the complete run (a screenshot is ok)?


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

0 Kudos
online11
Contributor
Contributor
Jump to solution

SnipImage.jpeg

Powercli Version: 6.3 R1 Build 3737840

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks like $esxcli was not initialised properly.
Can you check if the Get-Cluster works?

Are there any ESXi nodes in the cluster that are perhaps powered off or not connected?


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

0 Kudos
online11
Contributor
Contributor
Jump to solution

Get-Cluster seems to be working ok. I have tried. Get-Cluster "Cluster Name" | Get-VM output is fine, all hosts are up and running. They are all 5.1 hosts. Should I be running this script on 6.0 hosts instead? Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That could be it, haven't tested against 5.1, only 5.5 and 6.x.

And I don't have any 5.1 left to test


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

0 Kudos
online11
Contributor
Contributor
Jump to solution

Thanks Luc for your effort and help. Much appreciated. I have run the script on Windows 2012 running Powercli this time worked without any prblem. It didnt run on Windows 10 , dont know why. Thanks a lot.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

On Windows 10 you have PowerShell 5, that could be the reason.


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

0 Kudos