VMware Cloud Community
alasdair_carnie
Enthusiast
Enthusiast
Jump to solution

Change iSCSI Initiator Name

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..............

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
admin
Immortal
Immortal
Jump to solution

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

0 Kudos
alasdair_carnie
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

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

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..........

0 Kudos