Forum Discussion

Patrick Rote's avatar
Patrick Rote
Iron Contributor
May 03, 2021

Escaping strings containing single quotes in PowerShell

Hi there,

How can i replace the single quote in the name cai.o'dowd as its causing errors

 

string is

 

i:0#.f|membership|cai.o'dowd_hod.com#ext#@xyz.onmicrosoft.com

 

Currently i'm doing the below and filtering based on userprinciplename

 

 

ObjectuserId = (Get-AzureADUser -Filter "UserPrincipalName eq '$($User.LoginName.replace('i:0#.f|membership|',''))'").ObjectId

 

Any ideas how i can do this in PowerShell?
I would also like to check if the field is null before processing it

 

Thanks in Advance

 

No RepliesBe the first to reply

Resources