VMware Cloud Community
virtualdive
VMware Employee
VMware Employee

LUN Masking rules: PowerCli

Hello All,

I have 250 ESX boxes running and most of them are having LUN masking rules setup. They wee obvously supposed to be deleted, but someone did not do it and left the company.

Is there any PowerCLI script that can help find the hosts with the LUN masking rules all at once.

Thanks,

Nick,

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

There is a sample script in Arnim's post called Masking LUN paths using PowerCLI.

Look for the section Unmasking the path.


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

Reply
0 Kudos
virtualdive
VMware Employee
VMware Employee

Cheers Luc,

I did go through that post. But the problem is still the same, you will have to login to each ESX host one by one to check the rules which is equivalent to my original problem. Might not be helpful in large environments.

Was looking for something through vCenter all at once.

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
Reply
0 Kudos
LucD
Leadership
Leadership

In the latest PowerCLI build you don't have to logon to each ESXi host afaik.

You could loop through all your ESXi servers, set up esxcli and unmask the paths.

Something like this

Get-VMHost | %{
  $esxcli = Get-EsxCli -VMHost $_  
  # Unmask the path for the host
}

Note, you only need to be connected to the vCenter


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

Reply
0 Kudos
virtualdive
VMware Employee
VMware Employee

Okay, please can you share the complete script on this? Also is there anything that will just tell which hosts are having Rules?

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
Reply
0 Kudos
LucD
Leadership
Leadership

Let's first check if we can find the masking claimrule(s)

Get-VMHost | %{
  Write-Host $_.Name
 
$esxcli = Get-EsxCli -VMHost $_
 
$esxcli.storage.core.claimrule.list() |   where {$_.Plugin -eq "MASK_PATH" -and $_.Matches -like "adapter=*"} }

Once we find the claimrules we should be able to use the rule number to unmask the LUNs.

Update: are you running vSphere 5.x ?


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

Reply
0 Kudos
virtualdive
VMware Employee
VMware Employee

thanks Luc,

NoI am running vsphere 4.x.

But the PowerCLI is 5.0.

When I run the script you gave, it gave me this error....

esx0xxx.dril.for.int
You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\findmsklun.ps1:3 char:71
+   $esxcli = Get-EsxCli -VMHost $_  $esxcli.storage.core.claimrule.list <<<< () |
    + CategoryInfo          : InvalidOperation: (list:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Regards,

'V'
thevshish.blogspot.in
vExpert-2014-2021
Reply
0 Kudos
LucD
Leadership
Leadership

The layout of the esxcli commands has changed between vSphere 4 and 5.

You will have to use the syntax that is used in Arnim's post I mentioned above. My example is for vSphere 5.

I think it should be

$esxcli = Get-EsxCli -VMHost $_

$esxcli.corestorage.claimrule.list() |

but I'm afraid I can test that right no, since I don't have access to a vSphere 4 environment.

Btw, that should be 2 seperate line !


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

Reply
0 Kudos