Working in a few different domains, that have different naming schema\'s. So I\'m writing a script that goes into each domain, and checks on their group membership.
Firs
Format-* cmdlets were made for displaying data to a user. Do not use them when further processing of the data is required/intended.
Format-*
Change
... | select samaccountname | Format-Table -HideTableHeaders | Out-String
to
... | select -Expand samaccountname -First 1
and your problem will disappear.