While migrating a small environment to vSphere today I ran into my nemesis Host Profiles again. When are they going to Fix these things? The fact that they are incapable of even rudimentary iSCSI configuration is embarrassing. I’m sure vmware will fix it, but until then I wrote a simple one-liner that will configure iSCSI on a new host.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span style="color: #ff4500;">$VMhost</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">Get-VMhost</span> <span style="color: #8b0000;">'ESX01'</span> <span style="color: #ff4500;">$ChapUserName</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">'vmware'</span> <span style="color: #ff4500;">$ChapPassword</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">'password'</span> <span style="color: #ff4500;">$SendTargets</span> <span style="color: #a9a9a9;">=</span> <span style="color: #8b0000;">'192.168.1.1'</span> <span style="color: #006400;"># Enable the software ISCSI adapter if not already enabled.</span> <span style="color: #ff4500;">$VMHostStorage</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">Get-VMHostStorage</span> <span style="color: #000080;">-VMHost</span> <span style="color: #ff4500;">$VMhost</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Set-VMHostStorage</span> <span style="color: #000080;">-SoftwareIScsiEnabled</span> <span style="color: #ff4500;">$True</span> <span style="color: #006400;">#sleep while iSCSI starts up</span> <span style="color: #0000ff;">Start-Sleep</span> <span style="color: #000080;">-Seconds</span> <span style="color: #800080;">30</span> <span style="color: #006400;"># By default vSphere will set the Target Node name to iqn.1998-01.com.vmware:<HostName>-<random number> </span> <span style="color: #006400;"># This script will remove everything after the hostname, set Chap auth, and add a send Target.</span> <span style="color: #006400;">#</span> <span style="color: #006400;"># Example iqn.1998-01.com.vmware:esx01-165435 would become iqn.1998-01.com.vmware:esx01</span> <span style="color: #ff4500;">$VMHostHba</span> <span style="color: #a9a9a9;">=</span> <span style="color: #0000ff;">Get-VMHostHba</span> <span style="color: #000080;">-VMHost</span> <span style="color: #ff4500;">$VMHost</span> <span style="color: #000080;">-Type</span> <span style="color: #8a2be2;">IScsi</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Where-object</span> <span style="color: #000000;">{</span> <span style="color: #ff4500;">$_</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">IScsiName</span> <span style="color: #a9a9a9;">-match</span> <span style="color: #8b0000;">"(?<IQN>iqn.1998-01.com.vmware:[^-]+)"</span><span style="color: #000000;">}</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Set-VMHostHba</span> <span style="color: #000080;">-IScsiName</span> <span style="color: #ff4500;">$Matches</span><span style="color: #a9a9a9;">.</span><span style="color: #000000;">IQN</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">Set-VMHostHba</span> <span style="color: #000080;">-ChapName</span> <span style="color: #ff4500;">$ChapUserName</span> <span style="color: #000080;">-ChapPassword</span> <span style="color: #ff4500;">$ChapPassword</span> <span style="color: #000080;">-ChapType</span> <span style="color: #8b0000;">"Required"</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">New-IScsiHbaTarget</span> <span style="color: #000080;">-Address</span> <span style="color: #ff4500;">$SendTargets</span> <span style="color: #000080;">-Port</span> <span style="color: #8b0000;">"3260"</span> <span style="color: #006400;">#restart the host to make sure everything took</span> <span style="color: #0000ff;">Restart-VMHost</span> <span style="color: #000080;">-VMHost</span> <span style="color: #ff4500;">$VMHost</span> <span style="color: #000080;">-Confirm:</span><span style="color: #ff4500;">$false</span> <span style="color: #a9a9a9;">|</span> <span style="color: #0000ff;">out-null</span> |
~Glenn
Hi Glenn,
Do you know it this still works with powercli 4.1? It looks like get-VMhostStorage is not working like it is supposed to in that version…
Get-VMHostStorage : 8/12/2010 9:13:21 AM Get-VMHostStorage Object reference not set to an instance of an object.
At line:1 char:35
+ $VMHostStorage = Get-VMHostStorage <<<< -VMHost "pbnvm16.petrobakken.pvt" | Set-VMHostStorage -SoftwareIScsiEnabled $True
+ CategoryInfo : NotSpecified: (:) [Get-VMHostStorage], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostStorage
Thanks,
Dan