Reputation: 105
I've got the following powershell line:
$items = Get-ChildItem -Path "C:\temp" -Filter "*ä*" -Recurse | Select FullName
I want to write those paths to a *.txt file:
foreach ($item in $items){
add-content -Path C:\temp\test.txt -Value $item -Force
}
Output in test.txt:
@{FullName=C:\temp\ä}
How can I only write the Value of FullName to the txt-file ? For example:
echo $item
and Output in Console:
C:\temp\ä
Upvotes: 1
Views: 8475
Reputation: 46730
Common gotcha with PowerShell. $items
is not an array of FullNames but an object array with a fullname property. (Array assuming more that one item was returned.)
$items = Get-ChildItem -Path "C:\temp" -Filter "*ä*" -Recurse | Select -Expand FullName
or
# Requires PowerShell v3.0 or above
$items = (Get-ChildItem -Path "C:\temp" -Filter "*ä*" -Recurse).Fullname
Upvotes: 7
Reputation: 63860
You should be able to do this:
foreach ($item in $items){
add-content -Path C:\temp\test.txt -Value $item.FullName -Force
}
Here's a common way to find this bit of info:
Get-ChildItem | Get-Member
Or the same with shorthands:
dir | gm
This will list all properties, methods, etc for the objects returned from Get-ChildItem
.
Upvotes: 0