首页 > 解决方案 > Powershell Core 读取文件元数据

问题描述

我需要一种在 macOS 上使用 Powershell Core 7.x 读取文件元数据的方法。

在 MS Windows 环境中,我能够使用Shell.ApplicationCOM 对象和getDetailsOf()方法来检索信息。但是,我在 macOS 上的 PowerShell Core 中找不到此选项。

我发现有人在 PowerShell 核心中使用外部命令(我猜有些是用 python 编写的)来检索信息,但我想只使用 PowerShell 来做到这一点。

有谁知道这是否可以通过 Powershell 内核实现?

谢谢

标签: macospowershellpowershell-core

解决方案


Start-Process您可以使用cmdlet 并捕获此过程的输出,而不是使用“Shell.Application COM 对象”来执行外部工具:

$f = New-TemporaryFile
Start-Process exiftool -ArgumentList "myImage.jpg" -RedirectStandardOutput $f.FullName -Wait
$result = Get-Content -Path $f.FullName
Remove-Item -Path $f.FullName

# Now, the result of the exiftool is available in $result for further processing

推荐阅读