In January this year I created a post about Easy NFS datastore setup with PowerCLI. In this post I showed how you can use a reference host to copy all the NFS share configurations to the new host. In this post I will show you how to do the exact same thing only for iSCSI Send targets. I finally find some time to write this post which I promised to write in part 2 of my PowerCLI and iSCSI series.
The following script will check the $REFHOST, in my case esx2.ict-freak.local for all the iSCSI Send targets configured on that host. After that the script will check if all the iSCSI Send targets exists on the $NEWHOST. If this is not the case the script will add the missing Send Targets.
$REFHOST = Get-VMHost "esx2.ict-freak.local" $NEWHOST = Get-VMHost "esx1.ict-freak.local" $REFHBA = Get-VMHostHba -VMHost $REFHOST -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"} foreach($target in (Get-IScsiHbaTarget -IScsiHba $REFHBA -Type Send)){ $target = $target.Address $NEWHBA = Get-VMHostHba -VMHost $NEWHOST -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"} If ((Get-IScsiHbaTarget -IScsiHba $NEWHBA -Type Send | Where {$_.Address -eq $target} -ErrorAction SilentlyContinue )-eq $null){ Write-Host "Target $($target) doesn't exist on $($NEWHOST)" -fore Red New-IScsiHbaTarget -IScsiHba $NEWHBA -Address $target | Out-Null } }
But there is more..