PowerCLI: Configure iSCSI one-liner
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.
$VMhost = Get-VMhost 'ESX01' $ChapUserName = 'vmware' $ChapPassword = 'password' $SendTargets = '192.168.1.1' # Enable the software ISCSI adapter if not already enabled. $VMHostStorage = Get-VMHostStorage -VMHost $VMhost | Set-VMHostStorage -SoftwareIScsiEnabled $True #sleep while iSCSI starts up Start-Sleep -Seconds 30 # By default vSphere will set the Target Node name to iqn.1998-01.com.vmware:<HostName>-<random number> # This script will remove everything after the hostname, set Chap auth, and add a send Target. # # Example iqn.1998-01.com.vmware:esx01-165435 would become iqn.1998-01.com.vmware:esx01 $VMHostHba = Get-VMHostHba -VMHost $VMHost -Type IScsi | Where-object { $_.IScsiName -match "(?<IQN>iqn.1998-01.com.vmware\:[^-]+)"} | Set-VMHostHba -IScsiName $Matches.IQN | Set-VMHostHba -ChapName $ChapUserName -ChapPassword $ChapPassword -ChapType "Required" | New-IScsiHbaTarget -Address $SendTargets -Port "3260" #restart the host to make sure everything took Restart-VMHost -VMHost $VMHost -Confirm:$false | out-null
~Glenn