VMware Cloud Community
IrishVM
Contributor
Contributor
Jump to solution

Problem getting Chap Flag with powershell

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
IrishVM
Contributor
Contributor
Jump to solution

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. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
IrishVM
Contributor
Contributor
Jump to solution

that worked thanks. 

0 Kudos