Solved

apostrophe causing issues with get-aduser

Posted on 2016-10-12
2
36 Views
Last Modified: 2016-10-12
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

0
Comment
Question by:Roccat
2 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41840470
Try like this:
$listboxselection = "Larry O'Reilly"

$a = Get-Aduser -Filter {displayname -eq $listboxselection} -Property displayname

Open in new window

0
 

Author Closing Comment

by:Roccat
ID: 41840486
THANK YOU!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
A brief introduction to what I consider to be the best editor for PowerShell.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question