# Newbee Help with Strings Please

**URL:** <https://forums.powershell.org/t/newbee-help-with-strings-please/7790>\
**Category:** PowerShell Help\
**Created:** [January 3, 2017, 6:52pm UTC](https://forums.powershell.org/t/newbee-help-with-strings-please/7790 "2017-01-03T18:52:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![logicalnz](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@logicalnz](https://forums.powershell.org/u/logicalnz)\
**Post date:** [January 3, 2017, 6:52pm UTC](https://forums.powershell.org/t/newbee-help-with-strings-please/7790/1 "2017-01-03T18:52:34Z")

</div>

Good Afternoon All,

I’m a complete newbee to powershell trying to get information into a string variable.

The String looks like this.

$LD = Get-ADUser -Filter {name -eq $SelectUser}|Select-Object -Property DistinguishedName|ft -AutoSize

What I’m trying to do is to store the output (currently being written to the screen) the the variable $LD

I know that the command;

Get-ADUser -Filter {name -eq $SelectUser}|Select-Object -Property DistinguishedName|ft -AutoSize

returns what I want, but cant seem to get the results into a string/

But all I get is Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData"

What do I need to do here please?

I’m a little lost!

With thanks

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 3, 2017, 6:56pm UTC](https://forums.powershell.org/t/newbee-help-with-strings-please/7790/2 "2017-01-03T18:56:20Z")

</div>

Format-Table does not produce strings, it produces formatting directives, so that’s what you’ve got in $LD. You’re thinking Format-Table produces strings because you see text on the screen, but there’s stuff going on under the hood that’s messing you up :).

Try piping it to Out-String instead of Format-Table.

Alternately,

```
$LD = Get-ADUser -Filter {name -eq $SelectUser} | Select-Object -ExpandProperty DistinguishedName
```

Would probably be what you want, without the table header Format-Table produces.

See also [https://devopscollective.gitbooks.io/the-big-book-of-powershell-gotchas/content/manuscript/format-right.html](https://devopscollective.gitbooks.io/the-big-book-of-powershell-gotchas/content/manuscript/format-right.html). And, if you’d like to just not ever get plagued by a “gotcha” again, check out “Learn Windows PowerShell in a Month of Lunches, 3rd Edition.”

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/newbee-help-with-strings-please/7790/3 "2024-05-16T20:39:37Z")

</div>


