Powershell 如何获取目录中最早LastWriteTime的文件?

Powershell 如何获取目录中最早LastWriteTime的文件?,powershell,Powershell,如果我有一个带有通配符的完整路径,如何获取具有最早LastWriteTime的文件 $fullpath = "myFolder:\foooBar*.txt" $theOldestFile = # What to write to get among the #fooBar*.txt that has the max LastWriteTime? 像这样: $fullpath = "myFolder:\foooBar*.txt" $theOldestFile

如果我有一个带有通配符的完整路径,如何获取具有最早LastWriteTime的文件

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = # What to write to get among the 
                 #fooBar*.txt that has the max LastWriteTime?
像这样:

$fullpath = "myFolder:\foooBar*.txt"
$theOldestFile = dir $fullpath | sort lastwritetime | select -First 1

“dir”命令是否可能在属于导入模块的函数中不起作用?请尝试使用get childitem。。。或者你有一些范围变量问题吗?不起作用。我认为我创建的PS驱动器即使具有全局作用域,也无法从属于导入模块的函数访问。可能吗?当您创建psdrive时?在同一模块中?模块加载之后/之前?在其他模块中?在$profile中?