【问题标题】:Filter Objects returned by Get-ChildItem过滤 Get-ChildItem 返回的对象
【发布时间】:2014-05-08 08:08:55
【问题描述】:

我查看了 Get-ChildItem 命令返回的对象的可用属性:

PS C:\> Get-ChildItem | Get-Member

此命令显示 Get-ChildItem 命令返回的对象具有属性“名称、全名、上次访问时间等...”

我声明了一个变量来检索以“程序”开头的对象:

PS C:\> $ChildItems_Program = Get-ChildItem -name 'Program*'

检查 $ChildItems_Program 中存储的内容

PS C:\> $ChildItems_Program
Program Files
Program Files (x86)

尝试从 $ChildItems_Program 中保存的第一个对象访问属性“Name、FullName、LastAccessTime”

PS C:\> $ChildItems_Program[0] | Select -Property Name, FullName, LastAccessTime

Name                                 FullName                             LastAccessTime
----                                 --------                             --------------

为什么我看不到上述命令的任何结果 - 它不应该返回保存在 $ChildItems_Program 中的第一个对象的属性吗? 谁能指导一下。

谢谢!

【问题讨论】:

    标签: powershell windows-7 powershell-2.0


    【解决方案1】:

    来自technet(相当于get-help get-childitem

    -Name
    Gets only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent.
    

    【讨论】:

    • 是的 CB,我发现命令:Get-ChildItem -name 'Program*' return a string[],要实际返回对象,我应该使用开关:-Filter 而不是 -Name .
    猜你喜欢
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多