I have the following code
@Wildcard_Array = @ ( '"' , '[' , ']' , '*' )
$SAMAccounts = Import-Excel -Path $PSScriptRoot\PulledData.xlsx | Where-Object -Property SAM_ACCOUNT_NAME -notcontains @Wildcard_Array
What I'm trying to accomplish is that no values are returned that contain wildcard values.
If I use this I can filter dates which I want to I just don't know how to filter out and values with wildcards/invalid options.
$SAMAccounts = Import-Excel -Path $PSScriptRoot\PulledData.xlsx | Where-Object -Property DT -eq (Get-Date -Hour 0 -Minute 0 -Second 0 -Format G | Select-Object -ExpandProperty SAM_ACCOUNT_NAME
Example:
SAM_ACCOUNT_NAME DT
!@$#* 1/11/2024
User1 1/11/2024
I've tried contains, notcontains, cnotconains, notlike, and inotlike but honestly I'm not sure what i'm doing wrong. Thank you so much for your time.
You could use
.IndexOfAnyin this case:Another option could be to convert your array into a regex pattern and use
-notmatch:-containslooks for an exact match in a collection, so it isn't an option:And
-likewould require to first escape the wildcard characters (can use[WildcardPattern]::Escapesimilar to[regex]::Escape) and then use additional wildcards. I wouldn't recommend this method in this case.