将项目(文件)路径提供给Get-ChildItem cmdlet时,它将提取文件信息,例如Name,LastWriteTime,Size等。
Get-ChildItem -Path D:\Temp\style.css
输出结果
Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 08-12-2017 10:16 393 style.css
要获取文件的完整属性,则需要使用fl *(Format-List *)管道命令。
Get-ChildItem -Path D:\Temp\style.css | fl *
输出结果
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\Temp\style.css
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\Temp
PSChildName : style.css
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
Mode : -a----
VersionInfo : File: D:\Temp\style.css
InternalName:
OriginalFilename:
FileVersion:
FileDescription:
Product:
ProductVersion:
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language:
BaseName : style
Target : {}
LinkType :
Name : style.css
Length : 393
DirectoryName : D:\Temp
Directory : D:\Temp
IsReadOnly : False
Exists : True
FullName : D:\Temp\style.css
Extension : .css
CreationTime : 08-12-2017 10:02:17
CreationTimeUtc : 08-12-2017 04:32:17
LastAccessTime : 08-12-2017 10:02:17
LastAccessTimeUtc : 08-12-2017 04:32:17
LastWriteTime : 08-12-2017 10:16:26
LastWriteTimeUtc : 08-12-2017 04:46:26
Attributes : Archive您可以通过流水线化Select-Object参数来获取特定属性。在上面的示例中,我们将显示文件名,属性,扩展名,创建时间,最后访问时间和最后写入时间。
Get-ChildItem D:\Temp\style.css | Select Name, Extension, CreationTime, LastAccessTime, LastWriteTime
输出结果
Name : style.css Extension : .css CreationTime : 08-12-2017 10:02:17 LastAccessTime : 08-12-2017 10:02:17 LastWriteTime : 08-12-2017 10:16:26
同样,您可以在同一命令中检索多个文件信息。每个文件名都需要用逗号(,)分隔。
PS D:\Temp> Get-ChildItem .\style.css, .\cars.xml