如何使用PowerShell来获取父文件夹的子项,并拿起最新的更新子文件夹?

$ var.droppath.TrimEnd()#是父文件夹

所有子文件夹都以“10。**”命名…

我可以使用以下行来获取所有子文件夹:

get-childitem $var.droppath.TrimEnd()|where-object {$_.name -match "10."} 

这是我得到的一个小孩的名单:

  PSPath : Microsoft.PowerShell.Core\FileSystem::\\sharespace\test1\10.00.1220.00 PSParentPath : Microsoft.PowerShell.Core\FileSystem::\\sharespace\test1\ PSChildName : 10.00.1220.00 PSProvider : Microsoft.PowerShell.Core\FileSystem PSIsContainer : True Name : 10.00.1220.00 Parent : CU Exists : True Root : \\sharespace FullName : \\sharespace\test1\10.00.1220.00 Extension : .00 CreationTime : 1/8/2011 3:24:01 PM CreationTimeUtc : 1/8/2011 7:24:01 AM LastAccessTime : 6/25/2011 2:51:33 AM LastAccessTimeUtc : 6/24/2011 6:51:33 PM LastWriteTime : 6/25/2011 2:51:33 AM LastWriteTimeUtc : 6/24/2011 6:51:33 PM Attributes : Directory BaseName : 10.00.4272.00 Mode : d---- 

我可以过滤最新的更新后的子文件夹吗?

这个例子假定通过“最新的更新子文件夹”你想使用LastWriteTime属性。

 Get-ChildItem "10.*" | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1