function RemoveIScsiTarget ($vmHostList, $address, $port) {
foreach ($vmHost in $vmHostList) {
$storageSystem = $vmHost | Get-VMHostStorage | Get-View
$storageSystem.UpdateViewData("storageDeviceInfo.hostBusAdapter")
$iScsiDevice = "vmhba33"
$iScsi = $storageSystem.StorageDeviceInfo.HostBusAdapter | where { $_.GetType().Name -eq "HostInternetScsiHba" }
$sendTarget = $iScsi | foreach { $_.ConfiguredSendTarget } | where { $_.Address -like $address -and $_.Port -like $port }
$sendTarget = $iScsi | foreach { $_.ConfiguredStaticTarget } | where { $_.Address -like $address -and $_.Port -like $port }
if ($sendTargets -ne $null -and $sendTargets.Count -gt 0) {
$storageSystem.RemoveInternetScsiSendTargets($iScsiDevice, $sendTarget)
}
if ($staticTargets -ne $null -and $staticTargets.Count -gt 0) {
$storageSystem.RemoveInternetScsiStaticTargets($iScsiDevice, $staticTarget)
}
}
}
RemoveIScsiTarget (Get-VMHost) "10.10.10.*" "*"
Online access to the latest VMworld Sessions & Labs and online services.
Learn morePurchase credits to redeem training and consulting services online.
Buy Now