Sounds like you want to use .trim(). If it's an empty string '' there won't be an error. If it's really $null, you can enable an experimental feature in powershell 7 like this:
Enable-ExperimentalFeature PSNullConditionalOperators
Restart powershell and then if $a is null, there's still no error. The same goes for any method.
${a}?.trim()