PowerCLI

 View Only
  • 1.  LUN Masking rules: PowerCli

    Broadcom Employee
    Posted Jun 21, 2012 03:23 PM

    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,



  • 2.  RE: LUN Masking rules: PowerCli

    Posted Jun 21, 2012 03:42 PM

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

    Look for the section Unmasking the path.



  • 3.  RE: LUN Masking rules: PowerCli

    Broadcom Employee
    Posted Jun 21, 2012 04:04 PM

    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.



  • 4.  RE: LUN Masking rules: PowerCli

    Posted Jun 21, 2012 04:11 PM

    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



  • 5.  RE: LUN Masking rules: PowerCli

    Broadcom Employee
    Posted Jun 21, 2012 04:17 PM

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



  • 6.  RE: LUN Masking rules: PowerCli

    Posted Jun 21, 2012 05:34 PM

    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 ?



  • 7.  RE: LUN Masking rules: PowerCli

    Broadcom Employee
    Posted Jun 22, 2012 07:18 AM

    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



  • 8.  RE: LUN Masking rules: PowerCli

    Posted Jun 22, 2012 07:36 AM

    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 !