Leon_Eric
VMware Employee
VMware Employee

powercli to set perenially-resevered flag to false on VMFS volume

Previous admin incorrectly set perennially-resevered to true on VMFS volume. I am seeing roughly 60 ESXi hosts attached to those datastores.

Can anyone share script for identify and correct them[set perennially-reserved to false] on these datastores with such ?

 

Thanks.

0 Kudos
8 Replies
LucD
Leadership
Leadership

You could try something like this

$dsName = 'MyDS'

$ds = Get-Datastore -Name $dsName
$luns = Get-ScsiLun -Datastore $ds | Select -ExpandProperty CanonicalName

Get-VMHost -Datastore $ds |
ForEach-Object -Process {
    $esxcli = Get-EsxCli -VMHost $_ -V2
    $esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Device} | %{
        $params = @{
            device = $_.Device
            perenniallyreserved = $false
        }
        $esxcli.storage.core.device.setconfig.Invoke($params)
    }
}


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

jmhmhn
Contributor
Contributor

Would this change all the DSs on all the ESXi hosts that have this currently set to true?  There are numerous DSs connected to numerous ESXi hosts that need this to be changed to false.

0 Kudos
LucD
Leadership
Leadership

No, the script doesn't first check if the setting is true.
It just sets all LUNs for a specific datastore on all ESXi nodes that know this datastore to false.

You could include a test.


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

0 Kudos
jmhmhn
Contributor
Contributor

Would it skip any RDMs that might be in use?  I only want to change the setting to false on VMFS DSs (LUNs)

0 Kudos
LucD
Leadership
Leadership

It will only handle the LUNs that make up the Datastore


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

0 Kudos
jmhmhn
Contributor
Contributor

thank you!

0 Kudos
jmhmhn
Contributor
Contributor

I tried the script with a wildcard but that did not work.  I needed to input each datastore individually.  We have numerous datastores that need to be changed and would like to use the wildcard.  I changed the first line in the script to $dsName -Like 'YourDatastore*' however the -Like cmdlet is not valid.  Does anyone know what the cmd would be to use a wildscard?

0 Kudos
LucD
Leadership
Leadership

You will have to loop through all the Datastores.
Each datastore has different LUNs.


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

0 Kudos