Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Is there a way to check if a variable that you have matches something inside an array?

$
0
0

Hi All,

I have a general question about powershell. I basically am looking to see of I had variable equal to something, is there a way that I could search an array and see if a value within an array has something also equal to that variable? So here's a piece of my current code that involves the question that I have:

$searchOUs = "OU=District,DC=csd,DC=local"

        $OUs = Get-ADOrganizationalUnit -filter * -SearchBase $searchOUs

        if($excludeYear = $OUs) {

        $excludePath = Get-ADOrganizationalUnit -Identity $excludeYear

        } 

        foreach($excludeUser in $excluded) {

            Move-ADObject -Identity $excludeUser -TargetPath "OU=District,DC=csd,DC=local"

            }   

    }

 

Basically what I want to do is have the variable $OUs be an array that contains all my array names. And part of my code that isn't included a read-host is ran to ask someone what is the $excludeYear. So basically in this scenario what I am asking is that let's suppose $excludeYear=2024 and that $OUs equals a bunch of different OU names in my AD and one of the OU names happens to be 2024. Is there a way I can say, in $OUs if one of the OU names equals $excludeYear do stuff. Sorry if I didn't explain it very well. If more information is needed please let me know.


Viewing all articles
Browse latest Browse all 8583

Trending Articles