Windows Powershell 命令返回数组

2019-09-30 15:06:30刘景俊


数组的每一个元素存放的是一个System.IO.DirectoryInfo对象。
当我们输出这些对象时,Powershell会自动帮我们把它转换成友好的文本格式。

PS C:Powershell> $result[0].gettype().fullname
System.IO.DirectoryInfo
PS C:Powershell> $result[0]
  Directory: C:Powershell
Mode        LastWriteTime   Length Name
----        -------------   ------ ----
d----    2011/11/23   17:25      ABC对于任何一个对象都可以使用Format-List * 查看它所有的属性和方法。

PS C:Powershell> $result[0] | fl *

PSPath      : Microsoft.PowerShell.CoreFileSystem::C:PowershellABC
PSParentPath   : Microsoft.PowerShell.CoreFileSystem::C:Powershell
PSChildName    : ABC
PSDrive      : C
PSProvider    : Microsoft.PowerShell.CoreFileSystem
PSIsContainer   : True
BaseName     : ABC
Mode       : d----
Name       : ABC
Parent      : Powershell
Exists      : True
Root       : C:
FullName     : C:PowershellABC
Extension     :
CreationTime   : 2011/11/23 17:25:53
CreationTimeUtc  : 2011/11/23 9:25:53
LastAccessTime  : 2011/11/23 17:25:53
LastAccessTimeUtc : 2011/11/23 9:25:53
LastWriteTime   : 2011/11/23 17:25:53
LastWriteTimeUtc : 2011/11/23 9:25:53
Attributes    : Directory