0

I use powershell very few times and I would like to do something very simple ... but for which I have not found a solution.

How do I remove the {} brackets from the result? From what I understand I am reading a property of the object

Get-DbaXESession -SqlInstance localhost -Session Logins | where-Object Status -eq 'Running' | select TargetFile

# this is the result
TargetFile                              
----------                              
{C:\Traces\Logins\XE_Logins_Tuesday.xel}

Thanks Alen

ACaps
  • 97
  • 1
  • 8
  • 1
    `select TargetFile` creates a new object with a `TargetFile` property copied from the input object. Use `ForEach-Object TargetFile` or `Select -Expand TargetFile` to get just the value(s) of the `TargetFile` property on the input. – Mathias R. Jessen May 03 '22 at 14:49
  • 1
    In short: [`Select-Object`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-object) (`select`) by default returns _a `[pscustomobject]` instance_ that has the _requested properties_ - even when you're only asking for a _single_ property. To get only that property's _value_, use `-ExpandProperty ` instead - see the [linked duplicate](https://stackoverflow.com/q/48807857/45375) for details and alternatives. – mklement0 May 03 '22 at 15:05
  • 1
    In your specific case, note that the `{...}` in the formatted output indicates that the `.TargetFile` property value is an _array_ (or similar collection), which happens to contain just _one_ element; you can reproduce this as follows: `[pscustomobject] @{ foo = @('bar') }` – mklement0 May 03 '22 at 15:07

0 Answers0