Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,635 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All
i want to export all users whose Titles or descriptions can be anything except AB AC, BA, BC. i am using the below query but i am not getting output.
$A ="(title -like '*A*' -and title -notlike '*B*' -and title -notlike '*C*' -and (title -like '*D*' -or title -like '*E*' -or title -like '*F*') -or (description -like '*A*' -and description -notlike '*B*' -and description -notlike '*C*' -and (description -like '*D*' -or description -like '*E*' -or description -like '*F*')"
Get-ADUser -Filter $A -Properties DisplayName,SamAccountName,EmailAddress,Userprincipalname|Select DisplayName,SamAccountName,EmailAddress,Userprincipalname| Export-csv C:\temp\list.csv -Notypeinformation
What's wrong with something simple, like:
$A = "
(
title -ne 'AB' -and
title -ne 'AC'
) -or
(
description -ne 'AB' -and
description -ne 'AC'
)
"
If you'd rather go for something more complex:
$A ="
(
title -like '*A*' -and
title -notlike '*B*' -and
title -notlike '*C*' -and
(
title -like '*D*' -or
title -like '*E*' -or
title -like '*F*'
)
) -or
(
description -like '*A*' -and
description -notlike '*B*' -and
description -notlike '*C*' -and
(
description -like '*D*' -or
description -like '*E*' -or
description -like '*F*'
)
)"
I think you're introducing ambiguity with the broad use of wildcard matches.