Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to retrieve specific file(s) information using Get-ChildItem in PowerShell?
When the item (file) path is provided to the Get-ChildItem cmdlet, it extracts the file information like Name, LastWriteTime, Size, etc.
Example
Get-ChildItem -Path D:\Temp\style.css
Output
Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 08-12-2017 10:16 393 style.css
Command
To get the full properties of the file then you need to use fl * (Format-List *) pipeline command.
Get-ChildItem -Path D:\Temp\style.css | fl *
Output
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
Command
You can get the specific properties by pipelining the Select-Object parameter. From the above example, we will display the File Name, attributes, extension, creation time, last access time and last write time.
Get-ChildItem D:\Temp\style.css | Select Name, Extension, CreationTime, LastAccessTime, LastWriteTime
Output
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
Similarly, you can retrieve multiple files information in the same command. Each filename needs to be separated by comma (,).
PS D:\Temp> Get-ChildItem .\style.css, .\cars.xml
Advertisements
