为什么Powershell的Format-List *不输出所有属性

Los*_*nos 4 powershell

当我做一个属性时... | Format-List,其中一个属性是Path.
当我执行此操作时,... | Format-List *Path属性丢失了。
为什么?

[DBG]: PS C:\Directory>> $MyInvocation.MyCommand | Format-List

Name        : 
CommandType : Script
Definition  : $MyInvocation.MyCommand | Format-List
Path        : 

[DBG]: PS C:\Directory>> $MyInvocation.MyCommand | Format-List *

HelpUri            : 
ScriptBlock        : $MyInvocation.MyCommand | Format-List *
Definition         : $MyInvocation.MyCommand | Format-List *
OutputType         : {}
Name               : 
CommandType        : Script
Visibility         : Public
ModuleName         : 
Module             : 
RemotingCapability : PowerShell
Parameters         : 
ParameterSets      : {}
Run Code Online (Sandbox Code Playgroud)

Mat*_*att 5

赞扬gms0ulman 的回答......

\n\n

PowerShell 根据 format.ps1xml 文件将对象显示到控制台。来自格式化文件概述

\n\n
\n

命令(cmdlet、函数和脚本)返回的对象的显示格式是使用格式化文件(format.ps1xml 文件)定义的。其中几个文件由 Windows PowerShell 提供,用于定义 Windows PowerShell\xe2\x80\x93 提供的命令返回的对象的显示格式...

\n
\n\n

当有指示时,PowerShell 有一种特定的方式来显示对象(如果没有另外指示)。在您的情况下,这来自文件 PowerShellCore.format.ps1xml。通过检查类型$MyInvocation.MyCommand我们知道它是一个System.Management.Automation.ScriptInfo对象。知道我们可以从上面的文件中提取格式详细信息。

\n\n
<View>\n    <Name>System.Management.Automation.ScriptInfo</Name>\n    <ViewSelectedBy>\n        <TypeName>System.Management.Automation.ScriptInfo</TypeName>\n    </ViewSelectedBy>\n\n\n    <ListControl>\n        <ListEntries>\n            <ListEntry>\n               <ListItems>\n                    <ListItem>\n                        <PropertyName>Name</PropertyName>\n                    </ListItem>\n                    <ListItem>\n                        <PropertyName>CommandType</PropertyName>\n                    </ListItem>\n                    <ListItem>\n                        <PropertyName>Definition</PropertyName>\n                    </ListItem>\n                    <ListItem>\n                        <PropertyName>Path</PropertyName>\n                    </ListItem>\n                </ListItems>\n            </ListEntry>\n        </ListEntries>\n    </ListControl>\n</View>\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以我们看到它将尝试显示 Name、CommandType、Definition 和Path。如您所知,为所有属性指定 * 将显示对象1的所有现有属性

\n\n

路径当然是空的,因为你从哪里运行它。

\n\n

1该声明的一个小例外是一些常见的对象属性被隐藏到 *. 在这种情况下用于-Force显示所有内容。无论您是否知道他们的名字,都可以访问它们。

\n