Escaping strings containing single quotes in PowerShell

How can i replace/escape 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.