PowerCLI

 View Only
  • 1.  Change iSCSI Initiator Name

    Posted Jul 28, 2010 11:29 AM

    Hi,

    I'm writing a script to configure the iscsi initiator on multiple hosts and have come up with this

    Import-Csv -Path "c:\Tools\Powershell\CSV\hostconfig.csv" | %{

    $StorageSystem = Get-View (Get-VMHostStorage -VMHost (Get-VMHost -Name $_.esxHost)).ID

    $StorageSystem.UpdateSoftwareInternetScsiEnabled( $true )

    $StorageSystem.StorageDeviceInfo.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{

    $HbaName = $_.Device

    }

    $initName = $_.initname

    $StorageSystem.UpdateInternetScsiName $initName

    $iSendTarget1 = New-Object VMware.Vim.HostInternetScsiHbaSendTarget

    $iSendTarget1.Address = "10.10.10.1"

    $iSendTarget1.Port = "3260"

    $SendTargets = $iSendTarget1

    $StorageSystem.AddInternetScsiSendTargets( $HbaName, $SendTargets )

    Get-VMHostStorage -VMHost $hst -RescanAllHba -RescanVmfs

    }

    I am however stuck as to changing the initiator name. I need to do this for security on my SAN. I have used a csv file for the main variables and can extract the new name I want to set, but I cannot figure out how to set it.

    Any help would be appreciated.

    Thanks,

    Alasdair..............



  • 2.  RE: Change iSCSI Initiator Name
    Best Answer

    Posted Jul 28, 2010 01:21 PM

    The UpdateInternetScsiName method needs 2 parameters, the current name and the new name.

    Can you give this a try ?

    Import-Csv -Path "c:\Tools\Powershell\CSV\hostconfig.csv" | %{
    	$esxImpl = Get-VMHost $_.esxHost
    	$esx = $esxImpl | Get-View
    	$StorageSystem = Get-View $esx.ConfigManager.StorageSystem
    
    	$StorageSystem.UpdateSoftwareInternetScsiEnabled( $true )
    	
    	$StorageSystem.StorageDeviceInfo.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{
    		$HbaName = $_.Device
    	}
    
    	$StorageSystem.UpdateInternetScsiName($HbaName,$_.initName)
    	
    	$iSendTarget1 = New-Object VMware.Vim.HostInternetScsiHbaSendTarget
    	$iSendTarget1.Address = "10.10.10.1"
    	$iSendTarget1.Port = "3260"
    	$SendTargets = $iSendTarget1
    	$StorageSystem.AddInternetScsiSendTargets( $HbaName, $SendTargets )
    
    	Get-VMHostStorage -VMHost $esxImpl -RescanAllHba -RescanVmfs
    }
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Change iSCSI Initiator Name

    Posted Jul 28, 2010 01:49 PM

    You could also do this with cmdlets:

    Import-Csv -Path "c:\Tools\Powershell\CSV\hostconfig.csv" | %{
         $vmHost = Get-VMHost $_.esxHost
         Get-VMHostStorage -VMHost $vmHost | Set-VMHostStorage -SoftwareIScsiEnabled $true
    
         $iScsi = Get-VMHostHba -VMHost $vmHost -Type iScsi
         $iScsi | Set-VMHostHba -IScsiName $_.initName
    
         $iScsi | New-IScsiHba -Type send -Address "10.10.10.1" -Port "3260"
         Get-VMHostStorage -VMHost $vmHost -RescanAllHba -RescanVmfs
    }
    

    Regards,

    Dimitar

    -


    PowerCLI development team



  • 4.  RE: Change iSCSI Initiator Name

    Posted Jul 28, 2010 02:20 PM

    Hi Luc,

    Thanks. This works perfectly. Now all I have to do is try and understand what you changed and how it works :smileyhappy:

    On a slightly different note, did you ever crack how to configure iscsi multipathing and round robin with powershell. I found some posts regarding creating the switches and setting the load balancing policy to round robin, but nothing on the esxcli command portion.

    Cheers,

    Alasdair..........