Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

apostrophe causing issues with get-aduser

Posted on 2016-10-12
2
Medium Priority
?
84 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

636 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