Get-ChildItem的输出字符串值

时间:2013-10-21 14:05:00

标签: powershell get-childitem

我从Output sub-folder with the latest write access

获得了以下字符串
Get-ChildItem $FilePath | Sort {$_.LastWriteTime} -Descending | where {$_.PsIsContainer} |Select {$_.Name} -First 1 

但输出是:

$_.Name     
Username

我想要的输出是:

Username

我尝试通过以下方式格式化输出:

(Get-ChildItem $FilePath | Sort {$_.LastWriteTime} -Descending | where {$_.PsIsContainer} |Select {$_.Name} -First 1).name

但我不确定为什么它不起作用。

谢谢

1 个答案:

答案 0 :(得分:4)

试试这个:

Get-ChildItem $filepath | ? { $_.PsIsContainer} | Sort LastWriteTime -Descending | Select -expa  Name -First 1

我期待where-object,又称'?',以获得更好的效果。

使用select-object时,{}只需要计算属性,并且为了避免使用-expand参数,请使用{{1}}参数。

相关问题