Some XML files I'm looking at don't always include the name but
</NAME>
If I have trim() in the code it fails
[PSCustomObject]@{
Title = $customer.Name.Title.Trim()
FirstName = $customer.Name.First_Name.Trim()
LastName = $customer.Name.Last_Name.Trim()
EmailConsent = $emailConsent
EmailSoftOptIn = $emailSoftOptIn
}
How can I check so not apply trim() when attribute isn't there. I'm just researching to to see if I can assign to a variable and then check if it's empty but is this the best way.
This is linked to a previous post which was answered perfectly (I have put here for insight to full code)
Powershell access XML node with multiple attributes within a forloop
$customer.Name.Title -as [string] |% Trim('' + $customer.Name.Title).Trim()or regex:$customer.Name.Title -replace '^\s+|\s+$'