DEV Community

taijidude
taijidude

Posted on • Updated on

Check if an array contains a certain string

Last week I was searching through a huge array of strings by hand/eye. I was looking for certain active directory groups. I quickly realized how stupid this was and researched ("googled" ;-)) how to check if a powershell array contains a string. "-match" comes to the rescue here.

Example:

    $data = @('Zero','One','Two','Three')
    $data -match 'Two'
Enter fullscreen mode Exit fullscreen mode

Output:
Alt Text

Top comments (0)