Link to home
Start Free TrialLog in
Avatar of Roccat
RoccatFlag for United States of America

asked on

apostrophe causing issues with get-aduser

I have a list of users in a list box. One of the users has an apostrophe in their name and it causes error.  I know I can escape an apostrophe with another apostrophe but the list is loaded from the ad from members of a security group and they are loaded into the list as is with the one apostrophe.  What can I do to allow the get-aduser to complete with a user with an apostrophe in their name?

$listboxselection = "Larry O'Reilly"

$a = Get-Aduser -Filter "displayname -eq '$listboxselection'" -Property displayname
Remove-ADGroupMember "Coaches" -Members $a -confirm:$false

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dustin Saunders
Dustin Saunders
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roccat

ASKER

THANK YOU!