我想从Powershell命令Get-Item或Get-ItemProperty获得一些文件属性
Get-Item -Path c:\windows\system32\gdi32.dll | Select Name, Length, VersionInfo.ProductVersion, VersionInfo.FileVersion, CreationTime, LastAccessTime, LastWriteTime
Get-ItemProperty -Path c:\windows\system32\gdi32.dll -Name Name, Length, VersionInfo.ProductVersion, CreationTime, LastAccessTime, LastWriteTime这两个命令都没有给我VersionInfo.ProductVersion
发布于 2019-10-24 23:53:27
当您将VersionInfo.ProductVersion作为参数参数传递给函数时,PowerShell将其解释为字符串"VersionInfo.ProductVersion",并开始寻找具有该确切名称的属性。但是FileInfo对象没有这样的属性,这就是它不能工作的原因。
为了获取VersionInfo的属性值,您需要一个计算的属性
Get-Item ... |Select Name,Length,@{Name='ProductVersion';Expression={$_.VersionInfo.ProductVersion}},@{Name='FileVersion';Expression={$_.VersionInfo.FileVersion}},CreationTime,LastAccessTime,LastWriteTime您还可以提前将所有属性名称准备为数组:
$ItemProperties = @(
'Name'
'Length'
@{Name = 'ProductVersion'; Expression = {$_.VersionInfo.ProductVersion}}
@{Name = 'FileVersion'; Expression = {$_.VersionInfo.FileVersion}}
'CreationTime'
'LastAccessTime'
'LastWriteTime'
)
Get-Item ... |Select $ItemPropertieshttps://stackoverflow.com/questions/58550447
复制相似问题