Search This Blog

Thursday, May 13, 2010

VMware PowerCLI Powershell Script to copy iSCSI Targets from ESX host1 to host2

If there's a more efficient way to do this, please comment. I don't like that the New-IScsiHbaTarget  is looped for every IP address. I'd prefer to pipe the $esx1 IPtargets object to $esx2.

;Copy iSCSI targets from host1 to host2
$esx1 = get-vmhost hostname1*
$esx2 = get-vmhost hostname2*

foreach ($i in (get-vmhost $esx1 | Get-VMHostHba | where { $_.type -eq "iScsi" } | Get-IScsiHbaTarget) ) {  ( $esx2  | Get-VMHostHba | where { $_.type -eq "iScsi" } | New-IScsiHbaTarget -Address $i.address ) }