{"id":640,"date":"2012-03-16T22:01:33","date_gmt":"2012-03-16T21:01:33","guid":{"rendered":"http:\/\/www.amikkelsen.com\/?p=640"},"modified":"2012-05-07T20:26:37","modified_gmt":"2012-05-07T19:26:37","slug":"powershellesxcli-emc-vplex-changing-multipathing-policy","status":"publish","type":"post","link":"https:\/\/www.amikkelsen.com\/?p=640","title":{"rendered":"Powershell\/ESXCLI &#8211; EMC VPLEX changing multipathing policy"},"content":{"rendered":"<p>When connecting some storage systems to vSphere, vSphere sometime doesn&#8217;t select the most optimal multipathing policy.<\/p>\n<p>I came\u00c2\u00a0across\u00c2\u00a0the above problem when adding an EMC VPLEX storage system to a \u00c2\u00a0large vSphere 4.1 installation.<br \/>\nvSphere selected the Fixed path multipathing policy. In smaller\u00c2\u00a0environments\u00c2\u00a0this isn&#8217;t normally a problem , but when a Fixed policy is selected in a large\u00c2\u00a0environment\u00c2\u00a0with\u00c2\u00a0multiple\u00c2\u00a0datastores. vSphere selects the first path for each datastore, this results in almost all datastores uses the same path. The result is that the path will be overloaded.<\/p>\n<p><a href=\"http:\/\/www.emc.com\/collateral\/hardware\/white-papers\/h7118-using-vmware-virtualization-platforms-vplex.pdf\" target=\"_blank\">EMC&#8217;s best practices for EMC VMAX\/VPLEX<\/a> is to use Fixed policy with static load balancing or to use\u00c2\u00a0EMC PowerPath.<br \/>\nIn our\u00c2\u00a0environment Fixed or PowerPath wasn&#8217;t an option as we have multiple hosts and datastores, <del>so in close communication with EMC we chose to change the multipathing policy to Round Robin.<\/del>.<br \/>\nEMC has once now informed us that RR is only an option (not the best) if PowerPath or Fixed is not an option.<\/p>\n<p>Changing the policy for a few LUN&#8217;s won&#8217;t take long, if you only have a few hosts and a few datastores, but if you have multiple hosts with multiple datastores, the task is massive.<\/p>\n<p>Using Powershell and EsxCli the task is very easy and\u00c2\u00a0extremely\u00c2\u00a0fast.<br \/>\nThanks to Arnim van Lieshout\u00c2\u00a0(<a href=\"http:\/\/www.van-lieshout.com\/2011\/01\/esxcli-powercli\/\">http:\/\/www.van-lieshout.com\/2011\/01\/esxcli-powercli\/<\/a>) for the basic script.<\/p>\n<p><strong><span style=\"color: #ff0000;\">The below script illustrates how to set RoundRobin and not Fixed, this will be updated ASAP.<br \/>\nUntil then take a look at this post from LucD <a href=\"http:\/\/communities.vmware.com\/message\/1774139\">http:\/\/communities.vmware.com\/message\/1774139<\/a>\u00c2\u00a0<\/span><\/strong><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n&lt;pre&gt;function FuncMail {\r\n param($To, $From, $Subject, $Body, $smtpServer)\r\n $msg = new-object Net.Mail.MailMessage\r\n $smtp = new-object Net.Mail.SmtpClient($smtpServer)\r\n $msg.From = $From\r\n $msg.To.Add($To)\r\n $msg.Subject = $Subject\r\n $msg.IsBodyHtml = 1\r\n $msg.Body = $Body\r\n $smtp.Send($msg)\r\n}\r\n\r\n#load Vmware Module\r\nif ((Get-PSSnapin | Where-Object { $_.Name -eq &quot;VMware.VimAutomation.Core&quot; }) -eq $null) { Add-PSSnapin VMware.VimAutomation.Core }\r\n\r\n# ----------- Variables ---------------\r\n#vCenter\r\n$vcServer = &quot;vcenterserver&quot;\r\n$vCenterUser = &quot;vcenterusername&quot;\r\n$vCenterPWD = &quot;vcenterpassword&quot;\r\n$DC = &quot;*&quot; # Use * for all DC else replace * with datacenter name\r\n$cluster = &quot;*&quot; # Use * for all Clusters in DC else replace * with cluster name\r\n\r\n# LUN settings\r\n$LUNType = &quot;EMC Fibre Channel Disk*&quot;\r\n$psp = &quot;VMW_PSP_RR&quot;\r\n$satp = &quot;VMW_SATP_INV&quot;\r\n$iops = 10\r\n\r\n# ESX\r\n$esxUser = &quot;esxuser-root&quot;\r\n$esxPWD = &quot;esxuserpassword&quot;\r\n\r\n# Email\r\n$strEmailTo = &quot;to@mail.com&quot;\r\n$strEmailFrom = &quot;from@mail.com&quot;\r\n$strEmailSubject = &quot;PSP info '$vcServer' &quot;\r\n$strEmailSMTP = &quot;smtpserver.com&quot;\r\n\r\n# HTML\r\n$strHeadHTML = &quot;&lt;STYLE TYPE='text\/css'&gt;&quot;\r\n$strHeadHTML += &quot;TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}&quot;\r\n$strHeadHTML += &quot;TH{border-width: 1px;padding: 10px;border-style: solid;border-color: black; background-color:thistle}&quot;\r\n$strHeadHTML += &quot;TD{border-width: 0px;padding: 0px;padding-right: 5px;padding-left: 5px;border-style: solid;border-color: black}&quot;\r\n$strHeadHTML += &quot;&lt;\/STYLE&gt;&quot;\r\n\r\n$strBodyHTMLStart = &quot;&lt;H3&gt; Setting PSP multipath &amp; IOPS : &quot;\r\n$strBodyHTMLStart += Get-Date -Format g\r\n$strBodyHTMLStart += &quot;&lt;\/H3&gt;&quot;\r\n$strBodyHTMLStart += &quot;&lt;TABLE&gt;&lt;TR&gt; &lt;TH&gt;vCenter&lt;\/TH&gt; &lt;TH&gt;Datacenter&lt;\/TH&gt; &lt;TH&gt;Cluster&lt;\/TH&gt; &lt;TH&gt;Host&lt;\/TH&gt; &lt;TH&gt;Device&lt;\/TH&gt; &lt;TH&gt;SATP&lt;\/TH&gt; &lt;TH&gt;Old PSP&lt;\/TH&gt; &lt;TH&gt;New PSP&lt;\/TH&gt; &lt;TH&gt;IOPS&lt;\/TH&gt; &lt;TH&gt;Old Paths&lt;\/TH&gt; &lt;TH&gt;New Paths&lt;\/TH&gt;&lt;\/TR&gt;&quot;\r\n\r\n$strBodyHTMLinfoStart = &quot;&lt;H3&gt; PSP multipath &amp; IOPS not set : &quot;\r\n$strBodyHTMLinfoStart += Get-Date -Format g\r\n$strBodyHTMLinfoStart += &quot;&lt;\/H3&gt;&quot;\r\n$strBodyHTMLinfoStart += &quot;&lt;TABLE&gt;&lt;TR&gt; &lt;TH&gt;vCenter&lt;\/TH&gt; &lt;TH&gt;Datacenter&lt;\/TH&gt; &lt;TH&gt;Cluster&lt;\/TH&gt; &lt;TH&gt;Host&lt;\/TH&gt; &lt;TH&gt;Device&lt;\/TH&gt; &lt;TH&gt;SATP&lt;\/TH&gt; &lt;TH&gt;PSP&lt;\/TH&gt; &lt;TH&gt;Paths&lt;\/TH&gt;&lt;\/TR&gt;&quot;\r\n\r\n# ---------- Logic (Don't Change) --------------------\r\n\r\n$strBODYHTML = &quot;&quot;\r\n$strBodyExcludeHTML = &quot;&quot;\r\n\r\n#Connect to vCenter\r\nConnect-VIServer $vcServer -User $vCenterUser -Password $vCenterPWD| Out-Null\r\n\r\n#Get Datacenter Clusters\r\n$arrDC = Get-Datacenter -Name $DC | Sort Name\r\nif($arrDC){\r\n foreach($objDC in $arrDC){\r\n\r\n #Get Cluster list\r\n $arrCluster = Get-Cluster -Location $objDC -Name $cluster | Sort name\r\n if($arrCluster){\r\n foreach($objCluster in $arrCluster){\r\n\r\n #Connect to ESX hosts in cluster\r\n foreach ($esx in Get-VMHost -Location $objCluster | Sort Name) {\r\n\r\n Connect-VIServer $esx -User $esxUser -Password $esxPWD | Out-Null\r\n\r\n#Retrieve the esxcli instances and loop through them\r\n foreach($esxcli in Get-EsxCli -Server $esx.name) {\r\n\r\n #Write-Host $esx.Name -BackgroundColor Red\r\n\r\n # Change PSP for EMC VPLEX\/VMAX devices\r\n $arrDevice = $esxCli.nmp.device.list() | where {$_.PathSelectionPolicy -ne $psp -and $_.DeviceDisplayName -like $LUNType}\r\n if($arrDevice){\r\n foreach($myDevice in $arrDevice){\r\n #Write-Host &quot;Updating $($myDevice.Device)&quot; -ForegroundColor green\r\n $esxCli.nmp.device.setpolicy($null, $myDevice.Device, $psp)\r\n $esxcli.nmp.roundrobin.setconfig(0,$myDevice.device,&#x5B;long]$iops,&quot;iops&quot;,$false)\r\n\r\n $newPSP = $esxCli.nmp.device.list($myDevice.device)\r\n $newIOPS = $esxcli.nmp.roundrobin.getconfig($myDevice.device)\r\n $strBODYHTML += &quot;&lt;TR&gt; &lt;TD&gt;$($vcServer)&lt;\/TD&gt; &lt;TD&gt;$($objDC.Name)&lt;\/TD&gt; &lt;TD&gt;$($objCluster.Name)&lt;\/TD&gt; &lt;TD&gt;$($esx.Name)&lt;\/TD&gt; &lt;TD&gt;$($myDevice.Device)&lt;\/TD&gt; &lt;TD&gt;$($myDevice.StorageArrayType)&lt;\/TD&gt; &lt;TD&gt;$($myDevice.PathSelectionPolicy)&lt;\/TD&gt; &lt;TD&gt;$($($newPSP&#x5B;0]).PathSelectionPolicy)&lt;\/TD&gt; &lt;TD&gt;$($newIOPS.IOOperationLimit)&lt;\/TD&gt; &lt;TD&gt;$($myDevice.WorkingPaths)&lt;\/TD&gt; &lt;TD&gt;$($($newPSP&#x5B;0]).WorkingPaths)&lt;\/TD&gt;&lt;\/TR&gt;&quot;\r\n }\r\n }\r\n\r\n # Changes not set on\r\n $arrInfoDevice = $esxCli.nmp.device.list() | where {$_.PathSelectionPolicy -ne $psp -and $_.DeviceDisplayName -like $LUNType}\r\n if($arrInfoDevice){\r\n foreach($myInfoDevice in $arrInfoDevice){\r\n $strBODYHTMLinfo += &quot;&lt;TR&gt; &lt;TD&gt;$($vcServer)&lt;\/TD&gt; &lt;TD&gt;$($objDC.Name)&lt;\/TD&gt; &lt;TD&gt;$($objCluster.Name)&lt;\/TD&gt; &lt;TD&gt;$($esx.Name)&lt;\/TD&gt; &lt;TD&gt;$($myInfoDevice.Device)&lt;\/TD&gt; &lt;TD&gt;$($myInfoDevice.StorageArrayType)&lt;\/TD&gt; &lt;TD&gt;$($myInfoDevice.PathSelectionPolicy)&lt;\/TD&gt; &lt;TD&gt;$($myInfoDevice.WorkingPaths)&lt;\/TD&gt;&lt;\/TR&gt;&quot;\r\n }\r\n }\r\n\r\n #Change the default PSP for my SATP\r\n $esxcli.nmp.satp.setdefaultpsp($psp,$satp) | Out-Null\r\n }\r\n Disconnect-VIServer $esx.name -Confirm:$false\r\n }\r\n }\r\n }\r\n }\r\n}\r\n#Disconnect from vCenter\r\nDisconnect-VIServer $vcServer -Confirm:$false | Out-Null\r\n\r\n$strBodyHTMLEnd = &quot;&lt;\/TABLE&gt;&quot;\r\n$strBodyHTMLinfoEnd = &quot;&lt;\/TABLE&gt;&quot;\r\n\r\n# Collect the HTML\r\n$strHTML = &quot;&lt;HTML&gt;&lt;HEAD&gt;&quot;\r\n$strHTML += $strHeadHTML\r\n$strHTML += &quot;&lt;\/HEAD&gt;&lt;BODY&gt;&quot;\r\n$strHTML += $strBodyHTMLStart\r\n$strHTML += $strBODYHTML\r\n$strHTML += $strBodyHTMLEnd\r\n$strHTML += $strBodyHTMLinfoStart\r\n$strHTML += $strBODYHTMLinfo\r\n$strHTML += $strBodyHTMLinfoEnd\r\n$strHTML += &quot;&lt;\/BODY&gt;&lt;\/HTML&gt;&quot;\r\n\r\n# Email the collected data\r\nFuncMail -To $strEmailTo -From $strEmailFrom -Subject $strEmailSubject -Body $strHTML -smtpServer $strEmailSMTP\r\n<\/pre>\n<p><strong>Script explained<\/strong><\/p>\n<p>Line 20-24:<br \/>\nAdd you vCenter server name and the logon credentionls.<\/p>\n<p>Line 27-30:<br \/>\nLUNTYPE, is the storage type you want to change PSP and SATP for (you can set this to *, if you want you set the PSP and SATP for all datastores.<br \/>\nPSP, is the multipathing policy you want to change to.<br \/>\nSATP, is the storage array type you want to change the default to.<br \/>\nIOPS, is the number of IO&#8217;s to be send, before switching to the next path. vSphere default is 1000, EMC recommends 1, but I found 10 to work for me.<br \/>\nStephen Foskett has\u00c2\u00a0explained what is PSP and SATP in plain English\u00c2\u00a0\u00c2\u00a0<a href=\"http:\/\/blog.fosketts.net\/2011\/06\/06\/vmware-esx-vsphere-satp-psp-support-matrix\/\">http:\/\/blog.fosketts.net\/2011\/06\/06\/vmware-esx-vsphere-satp-psp-support-matrix\/<\/a>.<\/p>\n<p>Line 33-34:<br \/>\nChange the user to a user with root\u00c2\u00a0privileges.<br \/>\nChange the password to\u00c2\u00a0correspond with the user.<\/p>\n<p>Line 37-40:<br \/>\nChange the info to\u00c2\u00a0receive\u00c2\u00a0an report of what has been changed.<\/p>\n<p>Line 92-93:<br \/>\nSets the PSP and IOPS for each datastore.<\/p>\n<p>Line 95-96:<br \/>\nRetrieves the new settings (for\u00c2\u00a0verification) for \u00c2\u00a0each datastore.<\/p>\n<p>Line 101-107:<br \/>\nGenerates a list of datastores, where the PSP setting wasn&#8217;t able to be set.<br \/>\nRun the script again to set them.<\/p>\n<p>Line 111:<br \/>\nSets the hosts default datastore PSP and SATP.<br \/>\nIf your hosts connect to\u00c2\u00a0multiple\u00c2\u00a0different storage systems, I wouldn&#8217;t recommend setting this, but it&#8217;s to you.<\/p>\n<p>If you want to see an output on the screen of the progress of the script, uncomment the lines 85, 91<\/p>\n<p>Download the full RoundRobin script <a href=\"http:\/\/www.amikkelsen.com\/?dl_id=30\">here<\/a>.<\/p>\n<p>An exampel of what a report can look like:<br \/>\n<a href=\"http:\/\/www.amikkelsen.com\/images\/vplex_multipath_report.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"PSP, SATP and IOPS report for VPLEX \" src=\"http:\/\/www.amikkelsen.com\/images\/vplex_multipath_report.jpg\" alt=\"\" width=\"562\" height=\"214\" \/><\/a><\/p>\n<p>Post is updated after input from Josh Coen, <a href=\"http:\/\/www.valcolabs.com\/\">www.valcolabs.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When connecting some storage systems to vSphere, vSphere sometime doesn&#8217;t select the most optimal multipathing policy. I came\u00c2\u00a0across\u00c2\u00a0the above problem when adding an EMC VPLEX storage system to a \u00c2\u00a0large vSphere 4.1 installation. vSphere selected the Fixed path multipathing policy. In smaller\u00c2\u00a0environments\u00c2\u00a0this isn&#8217;t normally a problem , but when a Fixed policy is selected in\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.amikkelsen.com\/?p=640\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,21,4,13,16],"tags":[309,313,318,316,311,317,314,312,315,310],"class_list":["post-640","post","type-post","status-publish","format-standard","hentry","category-esx-i","category-powershell","category-scripting","category-tools","category-esx-x","tag-emc","tag-esxcli","tag-fixed-policy","tag-iops","tag-multipathing","tag-powerpath","tag-psp","tag-roundrobin","tag-satp","tag-vplex"],"_links":{"self":[{"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/posts\/640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=640"}],"version-history":[{"count":34,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/posts\/640\/revisions"}],"predecessor-version":[{"id":665,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=\/wp\/v2\/posts\/640\/revisions\/665"}],"wp:attachment":[{"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amikkelsen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}