I have run most of these commands from the command line and this works. Seems when I added the foreach to this script it does not work. Any ideas?
$hosts = Get-VMHost
foreach ($vmhost in $hosts){
$hostsdetails = Get-View $vmhost
$hostiscsi = $hostdetails.Config.StorageDevice.HostBusAdapter | where {$_.Key -like "*InternetScsi*"}
#trying to see if this call is working it is not
$hostdetails.Config.StorageDevice.HostBusAdapter | where {$_.Key -like "*Internet*"}
$again this shows as blank
$hostiscsi
foreach ($iscsihba in $hostiscsi){
$chapon = $iscsihba.AuthenticationProperties.ChapAuthEnabled
$chapon
if ($chapon -eq "False") {[array]$Hostmisschap = ($Hostmisschap + $vmhost)
}
}
}
$Hostmisschap
You're right, there were a few other problems.
Try this
$hosts = Get-VMHost
$Hostmisschap = @() foreach ($vmhost in $hosts){ $hostdetails = Get-View $vmhost
$hostiscsi = @($hostdetails.Config.StorageDevice.HostBusAdapter | where {$_.Key -like "*InternetScsi*"}) foreach ($iscsihba in $hostiscsi){ $chapon = $iscsihba.AuthenticationProperties.ChapAuthEnabled if (!$chapon) { $Hostmisschap += $vmhost.Name } } } $Hostmisschap
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suspect you have a typo in
$hostsdetails = Get-View $vmhost
Shouldn't that be
$hostdetails = Get-View $vmhost
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Well that may have been part of it. But when I run the script I still get 0 results. One Host has Chap the other does not so I should have one host being displayed at the end.
You're right, there were a few other problems.
Try this
$hosts = Get-VMHost
$Hostmisschap = @() foreach ($vmhost in $hosts){ $hostdetails = Get-View $vmhost
$hostiscsi = @($hostdetails.Config.StorageDevice.HostBusAdapter | where {$_.Key -like "*InternetScsi*"}) foreach ($iscsihba in $hostiscsi){ $chapon = $iscsihba.AuthenticationProperties.ChapAuthEnabled if (!$chapon) { $Hostmisschap += $vmhost.Name } } } $Hostmisschap
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
that worked thanks.