Home ยป PowerShell ยป PowerShell GetDetailsOf file in Folder

PowerShell GetDetailsOf file in Folder

Folder.GetDetailsOf() method in PowerShell is used to get the information about the file in the folder. It returns the file details like file type, size, length, file name, or file last modified date time.

In this article, we will discuss how to use the PowerShell GetDetailsOf() method of Windows Shell with the help of an example.

We will use the PowerShell GetDetailsOf() method to retrieve video file metadata like file type and video length.

PowerShell GetDetailsOf method

GetDetailsOf() method of the Windows Shell accepts 2 parameters, a file object, and an integer value.

The GetDetailsOf() method syntax:

retVal = Folder.GetDetailsOf(
  vItem,
  iColumn
)

vitem = Folderitem object. Specify the file object for which you want to retrieve information.

iColumn = an integer value to retrieve the information for the folder or file object.

For example to retrieve the file name, use below

Folder.GetDetailsOf(fileObject,0)

Cool Tip: How to rename part of the file name in PowerShell!

PowerShell GetDetailsOf to get video file metadata

Use the PowerShell GetDetailsOf method to retrieve the file details like its type, name, size, or other properties.

In the following PowerShell script, we use the PowerShell GetDetails() to get video file metadata like video file length, and its type.

$filePath = "D:\PS"
# create shell object
$shell = New-Object -ComObject Shell.Application

# Create the folder object object
$folderObject = $shell.NameSpace($filePath)

# Create the file object, specify the video file name
$fileObject = $folderObject.ParseName("PowerShell-Check-File-Exists.mp4")

# Get the video file name
$folderObject.GetDetailsOf($fileObject,0)

# Get the video file size
$folderObject.GetDetailsOf($fileObject,1)

# Get the video file type
$folderObject.GetDetailsOf($fileObject,2)

# Get the video file length
$folderObject.GetDetailsOf($fileObject,27)

In the above PowerShell script, we have created a Shell object using Shell.Application.

Windows Shell has the GetDetailsOf() method on the folder to get the details of files in the folder.

We have created a folder and file object to get details about the video file.

To get the file name, use GetDetailsOf() method and specify the file object and integer, it returns the file name.

$folderObject.GetDetailsOf($fileObject,0)  ๐Ÿ‘‰๏ธ PowerShell-Check-File-Exists.mp4

To get the video file length, use GetDetailsOf() method and pass the file object and 27. It returns the video file length in PowerShell.

$folderObject.GetDetailsOf($fileObject,27)  ๐Ÿ‘‰๏ธ 00:09:03

The output of the above PowerShell script to get video file metadata using the PowerShell GetDetails() method is:

PowerShell-Check-File-Exists.mp4
112 MB
MP4 File
00:09:03

Cool Tip: How to get file metadata in PowerShell!

Conclusion

I hope the above article to use PowerShell GetDetailsOf() method of Windows Shell is helpful to you.

You can use the GetDetailsOf() method to get details about the item in the folder.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.