Hi,
I am trying to change the path policy setting for the Raw Device Mappings (RDMs) in our environment from "Round Robin" to "Fixed". We are using RDM LUNs for clustering, but it turns out that VMWare currently doesn't support Round Robin path policy in RDMs. I found many scripts to change the setting for all LUNs, but I just want to change the setting for RDMs and nothing else.
Any ideas on how to write a powercli script to do that would be greatly appreciated!
Thanks,
-Eugenio
Try something like this
foreach($vm in (Get-View -ViewType VirtualMachine)){ $vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{ if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){ $diskUUID = $_.Backing.LunUuid.Substring(10,32) $esx = Get-View $vm.Runtime.Host $lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID} if($lun){ Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName | where {$_.MultiPathPolicy -eq "RoundRobin"} | Set-ScsiLun -MultipathPolicy Fixed
} } } }
It's based on the logic I used in my LUN report – datastore, RDM and node visibility post.
Note that the script runs through all your VM and will check the path policy for all RDM disks. If you want to limit this to a specific set of VMs, then you could use the Filter parameter on the Get-View cmdlet on the first line.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
foreach($vm in (Get-View -ViewType VirtualMachine)){ $vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{ if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){ $diskUUID = $_.Backing.LunUuid.Substring(10,32) $esx = Get-View $vm.Runtime.Host $lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID} if($lun){ Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName | where {$_.MultiPathPolicy -eq "RoundRobin"} | Set-ScsiLun -MultipathPolicy Fixed
} } } }
It's based on the logic I used in my LUN report – datastore, RDM and node visibility post.
Note that the script runs through all your VM and will check the path policy for all RDM disks. If you want to limit this to a specific set of VMs, then you could use the Filter parameter on the Get-View cmdlet on the first line.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD! This was very helpful!!
@LUCD : I have small doubt in the below script.
How do we find the attributes supported to so & so commands,for exam. you have mentioned in the below exam.$esx.Config.StorageDevice.ScsiLun
How can we avail these pramateres like .config.storagedevice.etc..
If we keep pressing tab continiously, we would get parameters related to it, but if you can get a list of the all the avialble parameters listout in commands, will help us to filter it out..
These vSphere objects are described in the SDK Reference.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What if you want to do cluster by cluster?
Also, I'm getting..
If the MultipathPolicy parameter is set to 'Fixed', you must
specify the PreferredPath parameter.
Luc, can you please update how to run it for a list of already identified VMs?
$VMlist = Get-Content -path "C:\vmlist.txt"
foreach ($vm in $vmlist)
{
foreach($vm in (Get-View -ViewType VirtualMachine)){
$vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
$diskUUID = $_.Backing.LunUuid.Substring(10,32)
$esx = Get-View $vm.Runtime.Host
$lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID}
if($lun){
Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName |
where {$_.MultiPathPolicy -eq "RoundRobin"} |
Set-ScsiLun -MultipathPolicy Fixed
}
}
}
}
Try like this.
This version also fixes the issue with the missing PreferredPath parameter.
$filter = [string]::Join('|',(Get-Content -path "C:\vmlist.txt"))
foreach($vm in (Get-View -ViewType VirtualMachine -Filter @{'Name'=$filter})){
$vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
$diskUUID = $_.Backing.LunUuid.Substring(10,32)
$esx = Get-View $vm.Runtime.Host
$lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID}
if($lun){
$lunObj = Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName |
where {$_.MultiPathPolicy -eq "RoundRobin"}
if($lunObj){
$path = Get-ScsiLunPath -ScsiLun $lunObj | Get-Random
Set-ScsiLun -ScsiLun $lunObj -MultipathPolicy Fixed -PreferredPath $path
}
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, but i need to set the path policy to MRU since it's an AP array.So I believe I should use only till
$path = Get-ScsiLunPath -ScsiLun $lunObj | Get-Random
Set-ScsiLun -ScsiLun $lunObj -MultipathPolicy MostRecentlyUSed
and rest of the script remains the same.
Correct, something like this
$filter = [string]::Join('|',(Get-Content -path "C:\vmlist.txt"))
foreach($vm in (Get-View -ViewType VirtualMachine -Filter @{'Name'=$filter})){
$vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
$diskUUID = $_.Backing.LunUuid.Substring(10,32)
$esx = Get-View $vm.Runtime.Host
$lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID}
if($lun){
Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName |
where {$_.MultiPathPolicy -ne "RoundRobin"} |
Set-ScsiLun -MultipathPolicy RoundRobin
}
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, will check it out
One question though. I wanted to make sure if my VM has more than 1RDMs attached the script should be able to change the path policy for all the disks and not stop after one. I did not see the logic to traverse across the disks and do the configurations (like foreach disk or something), hence the question.
Sorry for the ignorance
The 3th line starts a loop that runs through all the devices connected to the VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome. Thanks again!