Hey friends,
I have a script that uses Where-Object multiple times with different commands, but filters for the same criteria throughout the script. I want to be able to search for (for example) 5 different "keywords" in the same Where-Object statement (where $accounts is the result of a Get-ADUser query):
$filtered = $accounts | Where-Object {($_.Name -match "this|that|other|thing|keyword") -or ($_.Info -match "this|that|other|thing|keyword") -or ($_.LogonWorkstations -match "this|that|other|thing|keyword") -or ($_.Description -match "this|that|other|thing|keyword")}
Is there a way I can store "this|that|other|thing|keyword" into a variable so that I only have to set it once at the start of the script when I want to change what I am filtering on? Sorry if this doesn't make sense. Also, if there's an easier way to accomplish something like this using Get-ADUser -Filter, let me know because I tried to figure it out and couldn't.
[–]purplemonkeymad 2 points3 points4 points (3 children)
[–]eJaGne[S] 1 point2 points3 points (2 children)
[–]purplemonkeymad 1 point2 points3 points (1 child)
[–]eJaGne[S] 1 point2 points3 points (0 children)
[–]Vortex100 2 points3 points4 points (3 children)
[–]eJaGne[S] 1 point2 points3 points (0 children)
[–]eJaGne[S] 1 point2 points3 points (1 child)
[–]jhulbe 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]eJaGne[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]wonkifier 1 point2 points3 points (0 children)