简体   繁体   English

使用 Powershell 驱动 Windows 资源管理器中的高级搜索 - 如何将 pipe Out-GridView 转换为 ZAEA23489CE0AA9B640Z06EBB2?

[英]Using Powershell to drive advanced search in Windows Explorer - How to pipe Out-GridView to Windows Explorer?

I have a folder on a remote computer containing security camera video footage.我在远程计算机上有一个文件夹,其中包含安全摄像头视频片段。 I want to only search the *.mp4 files for those that are created between 2300 and 0600. The code:我只想在 *.mp4 文件中搜索在 2300 和 0600 之间创建的文件。代码:

$root = "F:\ispy\video\SWVL"  
(Get-ChildItem -Path $root) | Where-Object {$_.lastWriteTime.TimeOfDay.Hours -gt 23 -or $_.LastWriteTime.TimeOfDay.Hours -lt 06} | ls | Out-GridView -PassThru 

Does this perfectly, and passes the output (file list) to a PowerShell gridview.... BUT, I need the out to show the files in Windows Explorer.完美地做到这一点,并将 output(文件列表)传递给 PowerShell gridview....但是,我需要在 ZAEA230Z6B28CE0 中显示文件

I'm essentially trying to use a PowerShell script as an advanced search filter.我实际上是在尝试使用 PowerShell 脚本作为高级搜索过滤器。

Hoping someone has some ideas.希望有人有一些想法。 Eventually, I'm planning to use this as a flow -somehow- in power automate and power apps.... but need to crack this first part.最终,我计划将其用作电源自动化和电源应用程序中的流程……但需要破解第一部分。

Thanks, Gregg AZ谢谢,格雷格 AZ

Your use case is not valid.您的用例无效。 Windows Explorer Windows 资源管理器

You can, in your script, do something like this.. (dropping the call to Out-GridView as it's not needed for your end results)你可以在你的脚本中做这样的事情..(放弃对 Out-GridView 的调用,因为你的最终结果不需要它)

# find those files
Get-ChildItem -Path  'F:\ispy\video\SWVL'   |  
Where-Object {
$PSItem.lastWriteTime.TimeOfDay.Hours -gt 23 -or 
$PSItem.LastWriteTime.TimeOfDay.Hours -lt 06} | 
# copy them to a temp location
Copy-Item -Destination 'SomeTempPath' -Verbose

# open explorer in that location
Invoke-Item -Path 'SomeTempPath'

... then delete that location when you are done. ...然后在完成后删除该位置。

Windows Explorer-specific search/filtering is only possible in Windows Explorer. Windows Explorer 特定的搜索/过滤只能在 Windows Explorer 中进行。 So, that means you can only search to get a specific property, then use GUI automation to send that to the Windows Explorer search box.因此,这意味着您只能搜索以获取特定属性,然后使用 GUI 自动化将其发送到 Windows Explorer 搜索框。

Otherwise, just skip the script and know this to avoid overcomplicating what you are after.否则,只需跳过脚本并了解这一点,以避免使您所追求的过于复杂。

In Windows Explorer, you can filter the files by date in File Explorer using the date: keyword.在 Windows 资源管理器中,您可以使用 date: 关键字在文件资源管理器中按日期过滤文件。 You can use this keyword to find files created before, on or after a certain date.您可以使用此关键字查找在某个日期之前、当天或之后创建的文件。 You can use the “>” and “<” signs to find files created after or before the given date.您可以使用“>”和“<”符号来查找在给定日期之后或之前创建的文件。 “>=” and “<=” also apply here. “>=”和“<=”也适用于此。 While you can manually type the date, File Explorer provides a simple calendar that will show up every time you type date: on the search box.虽然您可以手动输入日期,但文件资源管理器提供了一个简单的日历,每次您输入日期时都会显示:在搜索框中。

在此处输入图像描述

In a script, you'd have to duplicate the aforementioned.在脚本中,您必须复制上述内容。 Thus capturing the date in your search, opening Windows Explorer and using SendKeys or AutoIT to select the search box and paste the info then sending enter.因此在搜索中捕获日期,打开 Windows Explorer 并使用 SendKeys 或 AutoIT 到 select 搜索框并粘贴信息然后发送回车。

Update as per my comment regarding the pop-up calendar.根据我对弹出日历的评论进行更新。 You can do this, in Windows Explorer to filter by date/date ranges您可以在 Windows Explorer 中按日期/日期范围过滤

Manually type it in manually, which of course you could GUI automate via SendKeys or AutoIT.手动手动输入,当然您可以通过 SendKeys 或 AutoIT 进行 GUI 自动化。 在此处输入图像描述

Click the down arrow on any date column.单击任何日期列上的向下箭头。 在此处输入图像描述

In the built-in Windows Sandbox on the latest WinOS builds, the popup still works from the Windows Explorer searchbox.在最新 WinOS 版本的内置 Windows 沙盒中,弹出窗口仍然可以从 Windows 资源管理器搜索框工作。

在此处输入图像描述

... but not on other host systems. ...但不是在其他主机系统上。

Update as per our last comments... Yet, if you are really trying to send to the Explore serachbox, then this kludge can do it,...根据我们最后的评论进行更新...但是,如果您真的想发送到 Explore serachbox,那么这个 kludge 可以做到,...

Start-Process -FilePath 'Explorer' 'd:\temp'
Add-Type -AssemblyName System.Windows.Forms
Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait('+{TAB}'*2)
[System.Windows.Forms.SendKeys]::SendWait('date: 04-Apr-20..11-Jan-21')
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait('{Enter}')

... but warning SendKeys is quirky, timing-wise, etc. Sometimes is works, sometimes it does not. ...但是警告SendKeys 是古怪的,时间方面的等等。有时有效,有时无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM