Use child-item result object in array

前端 未结 1 1708
遥遥无期
遥遥无期 2021-01-25 03:00

I encountered a problem in PowerShell in listing its child items.

$file = Get-ChildItem \\\\compname\\c$\\folder\\ -Recurse -Filter *filename.txt* |
        Sel         


        
相关标签:
1条回答
  • 2021-01-25 03:51

    You're still using PowerShell v2 or earlier. These early versions don't support member enumeration on arrays, which would allow you to access properties of array elements via the array object itself. Instead you get an empty result, because the array object does not have a property DirectoryName or FullName.

    If you can't upgrade to at least PowerShell v3 you can work around this issue with a loop:

    $file | ForEach-Object { $_.FullName }
    

    or by expanding the property:

    $file | Select-Object -Expand FullName
    
    0 讨论(0)
提交回复
热议问题