0

gci something | select {$_.FullName} | foreach {.\echoargs.exe $_} shows that what I thought was just a string gets passed to the executable as @{$_.FullName=C:\something}. If I try and "convert it even more to a string" with something like .ToString() it just gets added in as @{$_.FullName.ToString()= How can I get rid of this extra @{ formatting and pass only the string to an executable?

lcsondes
  • 484
  • 4
  • 16

1 Answers1

1

What you have experienced is that PowerShell sends a 'stringified' representation of the object(s) you have, like @{$_.FullName=C:\something}.

Get-ChildItem (gci) returns FileInfo or DirectoryInfo objects with lots of properties.
Piping that to Select-Object FullName then returns object(s) with one property, namely the FullName, but nevertheless, they are still objects, not strings.

What you really want is to send just the fullname path as string, so you need to either use

Select-Object -ExpandProperty FullName

or

(Get-ChildItem -Path something).FullName

to get (an array of) strings that will be sent to the external application.

Theo
  • 57,719
  • 8
  • 24
  • 41