I am new to Powershell and I am trying to exclude specific "GivenName" and "SN" when exporting results to a CSV.
This is my current script-
Get-ADUser -SearchBase "OU=Us00,OU=NA,Dd=corp,Dd=ads" -Filter {Enabled -eq $True} -Properties * | Select-Object GivenName, SN, DisplayName, Company, LastLogonDate |Where {($_.LastLogonDate -lt (Get-Date).AddDays(-30)) -and ($_.LastLogonDate -ne $NULL)} | Export-Csv -Path G:\Conduct\InactiveUsers.csv -NoTypeInformation
My goal is to Exclude any GivenName that may include the word "Agile" and OR exclude any SN that may include the word "External"
I have tried a where "is not" statement, but I am failing to reach my end goal. Any guidance or help would be appreciated
Get-ADUser -Filter 'Enabled -eq $True -and (GivenName -notlike "*Agile*" -or SN -notlike "*External*")'-isand-isnotoperators are for comparing types like"hello" -is [string]. Powershell uses-likeand-notlikefor text comparison. Check out examples of all the operators here: learn.microsoft.com/en-us/powershell/module/…