Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要通过powershell在windows中搜索具有最新时间戳的文件_Windows_Powershell - Fatal编程技术网

需要通过powershell在windows中搜索具有最新时间戳的文件

需要通过powershell在windows中搜索具有最新时间戳的文件,windows,powershell,Windows,Powershell,我有分配给我的项目,首先我需要找到它在服务器中的目录中的文件,我写的代码 $drive = get-psdrive |select root |select-string -pattern ':' Write-Host $drive foreach ($a in $drive) { Get-ChildItem $a -recurse -filter "*DBaEnvProd*" |select directory

我有分配给我的项目,首先我需要找到它在服务器中的目录中的文件,我写的代码

    $drive = get-psdrive |select root |select-string -pattern ':'
 Write-Host $drive

     foreach ($a in $drive)
        {
            Get-ChildItem $a -recurse -filter  "*DBaEnvProd*" |select  directory        
        }
there shd be one output a there will be only one dbenvprod on server
how to get one value 
我得到的输出

Get-ChildItem : Cannot find drive. A drive with name '@{Root=C' does not exist.
At D:\temp.ps1:6 char:26
+             Get-ChildItem  <<<< $a -recurse -filter  "*DBaEnvProd*" |select  directory
Get-ChildItem : Cannot find drive. A drive with name '@{Root=D' does not exist.
At D:\temp.ps1:6 char:26
+             Get-ChildItem  <<<< $a -recurse -filter  "*DBaEnvProd*" |select  directory
Get-ChildItem : Cannot find drive. A drive with name '@{Root=E' does not exist.
At D:\temp.ps1:6 char:26
+             Get-ChildItem  <<<< $a -recurse -filter  "*DBaEnvProd*" |select  directory
Get-ChildItem : Cannot find drive. A drive with name '@{Root=F' does not exist.
At D:\temp.ps1:6 char:26
+             Get-ChildItem  <<<< $a -recurse -filter  "*DBaEnvProd*" |select  directory
Get-ChildItem : Cannot find drive. A drive with name '@{Root=Z' does not exist.
At D:\temp.ps1:6 char:26
+             Get-ChildItem  <<<< $a -recurse -filter  "*DBaEnvProd*" |select  directory
添加-InputObject参数:

Select-String -InputObject {$_.Root} -Pattern ':'

我正在获取输出,但也收到了错误Get ChildItem:对路径“C:\Program Files x86\Tanium\Tanium Client”的访问被拒绝。在D:\temp.ps1:6 char:26+Get ChildItem,这是因为Get PSDrive返回的不仅仅是本地驱动器和映射的网络驱动器。iam在工具中使用它显示一行,然后此错误版权所有2010 BMC Software Ltd,版本:1.6.2连接到远程服务。。。已连接到远程主机。A:\C:\D:\E:\F:\G:\I:\J:\K:\Z:\正在关闭管道。读取HREMOTESTDERRORPOIPE时出错:ListenerRemoteStudOutPipeThread虽然此仅限代码的帖子可能会回答此问题,但请添加一个解释,说明为什么会这样做。
Select-String -InputObject {$_.Root} -Pattern ':'