question

SebastiaanCastenmiller-7985 avatar image
0 Votes"
SebastiaanCastenmiller-7985 asked RichMatheisen-8856 edited

match a value in an array

Hi,

I've got this script that tells me if a value exits in groups.name now I want it to tell me when it doesn't exist.

             ForEach($asset in $currentFlexAssets.data.attributes.name)
             {
                 ForEach($group in $groups.Name)
                 {
                     If ($asset -match $group)
                     {
                         Write-Host "Keep = " $asset 
                     }
                 }
             }

Is there something like If ($asset -match $group.name) ??


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 edited
         ForEach($asset in $currentFlexAssets.data.attributes.name)
             $Found = $false
             ForEach($group in $groups.Name)
                 If ($asset -match $group) {
                     Write-Host "Keep = " $asset
                     $Found = $true
                 }
             }
             if ($Found -eq $false) {
                 "Asset not found."
             }
         }

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

Why not this?

 ForEach($asset in $currentFlexAssets.data.attributes.name)
 {
     If ($groups.name -notcontains $asset){
         # do something
     }
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.