How do I convert a Powershell object to a string?

Hi All,
Powershell question...If I return an attribute e.g
[PS] C:\>Get-MailContact testuser1 | Select-Object DistinguishedName
How do I then convert the output...


into simply a string of "cn=testuser1,ou=Contacts,DC=testdom,dc=com" ?

Thanks in advance for any advice!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

One of many possibilities would be:
Get-MailContact testuser1 | Select-Object DistinguishedName | Out-String
Easier way
Get-MailContact testuser1 | %{$_. DistinguishedName }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davequinliskAuthor Commented:
Thanks for the responses so far.  The reason I ask for this is because I want to append the string into an LDAP:// connection string for a vb movehere method.

I might be missing something but If I run the code mentioned by BSonPosh and throw it into a variable I don't get the correct output but I get  just a blank line..?

If I use out-string I get the full distingquised name not just the string I need.  I can select the individual string but there is still whitespace surrounding it when I write-host.

Hope that makes sense and thanks for the help guys!
$testvar = Get-MailContact testuser1 | %{$_. DistinguishedName }
Write-Host $testvar

Open in new window

Is there a space between the $_. and Distinguishedname? There is NOT suppose to be
davequinliskAuthor Commented:
Thanks BSonPosh.
I definitly didn't have a space in there but I must of had a typo of some sort.  Re-Typed it in and all is well!

Many Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.