Escaping strings containing single quotes in PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-2316898%22%20slang%3D%22en-US%22%3EEscaping%20strings%20containing%20single%20quotes%20in%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2316898%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EHow%20can%20i%20replace%20the%20single%20quote%20in%20the%20name%26nbsp%3Bcai.o'dowd%20as%20its%20causing%20errors%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Estring%20is%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Ei%3A0%23.f%7Cmembership%7Ccai.o'dowd_hod.com%23ext%23%40xyz.onmicrosoft.com%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECurrently%20i'm%20doing%20the%20below%20and%20filtering%20based%20on%20userprinciplename%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EObjectuserId%20%3D%20(Get-AzureADUser%20-Filter%20%22UserPrincipalName%20eq%20'%24(%24User.LoginName.replace('i%3A0%23.f%7Cmembership%7C'%2C''))'%22).ObjectId%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20how%20i%20can%20do%20this%20in%20PowerShell%3F%3CBR%20%2F%3EI%20would%20also%20like%20to%20check%20if%20the%20field%20is%20null%20before%20processing%20it%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20Advance%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2316898%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Active%20Directory%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Contributor

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

 

0 Replies