欢迎各位兄弟 发布技术文章
这里的技术是共享的
在 PowerShell 中,Get-Location
是一个 cmdlet,用于获取当前的工作目录或位置。当你执行 Get-Location | gm
命令时,实际上是将 Get-Location
的输出传递给 gm
命令,这里的 gm
是 Get-Member
cmdlet 的别名,用于显示对象的类型及其成员(如属性和方法)。
Get-Location:
功能:返回当前的工作目录信息。
输出:通常是一个 System.IO.DirectoryInfo
对象,代表当前目录的位置。
管道符 |
:
功能:将前一个命令的输出作为下一个命令的输入。
Get-Member (gm):
功能:显示传递给它的对象的信息,包括对象的类型、属性和方法等。
参数:默认情况下,Get-Member
不需要额外参数即可工作,但它也可以接受参数来指定要查看的成员类型(如属性、方法等)。
Get-Location | gm
的结果当你运行这个命令时,它会显示 Get-Location
返回的对象的成员。由于 Get-Location
返回的是一个 DirectoryInfo
对象,Get-Member
将展示这个对象的所有可用属性和方法。
powershell深色版本1PS C:\> Get-Location | gm 2 3 TypeName: System.IO.DirectoryInfo 4 5Name MemberType Definition 6---- ---------- ---------- 7Create Method void Create(), void IObjec... 8CreateSubdirectory Method System.IO.DirectoryInfo C... 9Delete Method void Delete(), void Delet... 10Equals Method bool Equals(System.Object... 11GetDirectories Method System.IO.DirectoryInfo[]... 12GetFiles Method System.IO.FileInfo[] GetF... 13GetFileSystemInfos Method System.IO.FileSystemInfo[... 14GetHashCode Method int GetHashCode() 15GetObjectData Method void GetObjectData(System..... 16GetType Method type GetType() 17MoveTo Method void MoveTo(string destDir... 18Refresh Method void Refresh() 19ToString Method string ToString() 20Attributes Property System.IO.FileAttributes A... 21CreationTime Property datetime CreationTime {ge... 22CreationTimeUtc Property datetime CreationTimeUtc ... 23Exists Property bool Exists {get;} 24Extension Property string Extension {get;} 25FullName Property string FullName {get;} 26LastAccessTime Property datetime LastAccessTime {... 27LastAccessTimeUtc Property datetime LastAccessTimeU... 28LastWriteTime Property datetime LastWriteTime {g... 29LastWriteTimeUtc Property datetime LastWriteTimeUt... 30Name Property string Name {get;} 31Parent Property System.IO.DirectoryInfo P... 32Root Property System.IO.DirectoryInfo R...
MemberType: 表示成员的类型,如方法(Method)、属性(Property)等。
Definition: 提供了成员的具体定义,如方法的签名或属性的访问器。
TypeName: 显示对象的类型名称,在此例中为 System.IO.DirectoryInfo
。
通过这个命令,你可以了解到关于当前目录的更多信息,这对于编写更复杂的脚本或进行调试非常有帮助。