Solved

apostrophe causing issues with get-aduser

Posted on 2016-10-12
2
22 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Synchronize a new Active Directory domain with an existing Office 365 tenant
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now