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?
Asked
Active
Viewed 174 times
0

lcsondes
- 484
- 4
- 16
-
`Select-Object -ExpandProperty FullName` or `(Get-ChildItem -Path something).FullName` – Theo May 08 '21 at 11:03
-
This worked, thank you. If you'd like to post the same thing as an answer I'll accept it. – lcsondes May 08 '21 at 11:07
1 Answers
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