title: compare array to a foreach loop
body: <p>I'm trying to see if a value exists in an array. The index of function works when I manually put in a string. However when I use the value's of a foreach loop it doesn't work, what am I doing wrong? (see picture for more info)</p>
  <pre><code>                $groups = Get-ADGroup -Filter { GroupCategory -eq &quot;Security&quot; -and GroupScope -eq &quot;Global&quot;  } -Properties isCriticalSystemObject | Where-Object { !($_.IsCriticalSystemObject) -and !($_.Name -eq &quot;DnsUpdateProxy&quot;) }
                  
              $currentFlexAssets = (Get-ITGlueFlexibleAssets -filter_flexible_asset_type_id $api__flex_asset_id -filter_organization_id $api__org_id )                
              
              
              # Delete groups from IT Glue that no longer exist in AD
              $api__flex_asset_id = ''
              Foreach ($asset in $currentFlexAssets.data.attributes.name) {
                          
                  $asset
                  
                  $fa_index = [array]::indexof($groups.Name ,'$asset')
              
                  $fa_index
                                      
                  #if($fa_index -eq '-1') {
                  #   Write-Host &quot;Destroy = &quot; $asset 
                  #}
              }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/NI8TP.png" rel="nofollow noreferrer">powershell console</a></p>