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)
$groups = Get-ADGroup -Filter { GroupCategory -eq "Security" -and GroupScope -eq "Global" } -Properties isCriticalSystemObject | Where-Object { !($_.IsCriticalSystemObject) -and !($_.Name -eq "DnsUpdateProxy") }
$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 "Destroy = " $asset
#}
}
[array]::indexof($groups.Name, $asset)